我已经为发布和评论制作了控制器和模型。
我已经创建了我的帖子索引来调用我的添加评论视图。它工作正常,但添加评论视图打开另一个页面。
然后,我将添加评论视图包含在一个元素中,以便直接调用我的帖子页面,但是当我单击我的评论添加视图的提交按钮时,它不会保存任何内容。
当我查看提交按钮显示的链接时,它指向我的帖子索引视图。
如何使它起作用?
这是我的评论元素的代码
div class="comments form">
<?php echo $this->Form->create('Comment'); ?>
<fieldset>
<legend><?php echo __('Add Comment'); ?></legend>
<?php
$this->request->data['Comment']['user_id'] = $current_user['id'];
$this->request->data['Comment']['post_id'] = $post_id;
echo $this->Form->input('post_id', array('type' => 'hidden'));
echo $this->Form->input('user_id', array('type' => 'hidden'));
echo $this->Form->input('content');
?>
</fieldset>
<?php echo $this->Form->end(__('Submit')); ?>
</div>
这是调用该元素的索引帖子视图的代码的一部分
<div class="element">
<?php echo $this->element('add_comment', array('post_id' => $post['Post']['id'])); ?>
</div>
我必须补充一点,这个 div 类元素位于可点击的 div 中。但是对于我在视图中的其他按钮,单击效果很好。