douxieqiu0651 2012-11-08 11:29
浏览 92
已采纳

在OOP PHP中调用方法

I am very new at OOP, and i want to get things right at the first learning cycle.

I have a HTML form:

<?php
include("classes/Gaestebog.php");
$gaestebog = new Gaestebog();
?>
<html>
<head>
</head>
<body>
<form action="" method="post">
    <table>
        <tr>
            <td>Navn:</td>
            <td><input type="text" name="navn" value="Patrick" /></td>
        </tr>
        <tr>
            <td>Besked:</td>
            <td><input type="text" name="besked" value="Hej med dig !!" /></td>
        </tr>
        <tr>
            <td><input type="submit" name="opret" value="Opret" /></td>
        </tr>
    </table>
</form>

</body>
</html>

and a Guestbook class:

<?php
class Gaestebog {

    public function Gaestebog() {

    }

    public function getPosts() {

    }

    public function addPost() {

    }
}
?>

I want the :Guestbook to invoke the addPost method on form submission. How would i approach this?

  • 写回答

4条回答 默认 最新

  • doulao1934 2012-11-08 11:39
    关注
    <?php
    if(isset($_POST)) {
        include("classes/Gaestebog.php");
        $gaestebog = new Gaestebog();
    
        $data = array(
            'title' => $_POST['title'], 
            'author' => $_POST['author'],
            'content' => $_POST['content']
            // etc. 
        ); // Do not forget to validate your data
    
        $gaestebog->addPost($data);
    }
    ?>
    <!-- The HTML part... --> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现