Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP问题:如何将post/view的id传递给comment/view?_Php_Cakephp_Routing_Cakephp 1.3 - Fatal编程技术网

CakePHP问题:如何将post/view的id传递给comment/view?

CakePHP问题:如何将post/view的id传递给comment/view?,php,cakephp,routing,cakephp-1.3,Php,Cakephp,Routing,Cakephp 1.3,我现在在posts/view/id上 有编辑、删除帖子/视图/id中的评论的选项 如果我单击任何注释的编辑链接,则将执行注释/view/id 编辑评论后,我需要做=> $this->redirect(array('controller'=>'posts','action' => 'view',$id)); 这里$id将是posts的id 如何在评论/查看操作中获取帖子id 这是评论/编辑/id操作=> function edit($id) { $this->Co

我现在在posts/view/id上

有编辑、删除帖子/视图/id中的评论的选项

如果我单击任何注释的编辑链接,则将执行注释/view/id

编辑评论后,我需要做=>

$this->redirect(array('controller'=>'posts','action' => 'view',$id));
这里$id将是posts的id

如何在评论/查看操作中获取帖子id

这是评论/编辑/id操作=>

function edit($id) {
    $this->Comment->id = $id;
    if (empty($this->data)) {
        $this->data = $this->Comment->read();
    } else {
        if ($this->Comment->save($this->data)) {
            $this->Session->setFlash('Your comment has been updated.');
            $this->redirect(array('controller'=>'posts','action' => 'view',$id));
        }
    }
}
这是评论的编辑链接=>

echo $this->Html->link('Edit', array('controller'=>'comments','action'=>'edit',$comment['Comment']['id']));

我想您的评论数据库表定义了一个外键字段,它指向评论所属的帖子?我想,至少在这种情况下,这是最好的做法。
如果您已经这样实现了它,那么您可以通过使用当前查看的评论的外键字段轻松获得post_id


但是,您可能选择了不同的方法来连接模型。我认为使用该连接将是获取post_id的最简单方法。但届时,我们需要更多关于您的实现的信息

我想您的评论数据库表定义了一个外键字段,它指向评论所属的帖子?我想,至少在这种情况下,这是最好的做法。
如果您已经这样实现了它,那么您可以通过使用当前查看的评论的外键字段轻松获得post_id


但是,您可能选择了不同的方法来连接模型。我认为使用该连接将是获取post_id的最简单方法。但届时,我们需要更多关于您的实现的信息

评论/视图中不应该有$this->data['Comment']['post\u id']字段吗?除非你在帖子和评论之间有一些非正统的关系。所以
$this->redirect(数组('controller'=>'posts','action'=>'view',$this->data['Comment']['post_id']);

注释/视图中不应该有$this->data['Comment']['post\u id']字段吗?除非你在帖子和评论之间有一些非正统的关系。所以
$this->redirect(数组('controller'=>'posts','action'=>'view',$this->data['Comment']['post_id']);