使用 CakePHP 将视图嵌入到另一个视图中
我有一个新闻控制器,每个新闻项目都有一个“查看”操作。在每个新闻项目的“查看”操作中,我想包含另一个视图,即评论控制器的“添加”操作。 基本上,我需要在每个新闻项目的页面上添加一个表单来添加评论。 我有两种观点,但我无法将它们联系起来。我尝试使用元素,但似乎它没有呈现添加评论视图的视图。
我应该怎么办?
非常感谢!
编辑
元素中的代码:
<?php echo $this->Form->create('Comment', array('class' => 'big', 'url' => array('controller' => 'comments', 'action' => 'add', $news_id)));?>
<?php
echo $this->Form->input('comment', array('label' => false));
?>
Form->end(__('Submit', true));?>
查看代码:
<?php echo $this->element('add_comment', array('news_id' => $news['News']['id'])); ?>
I have a news controller with a 'view' action for each news item. In the 'view' action of each news item I would like to include another view, the 'add' action of the comments controller.
Basically, I need a form on each news item's page to add comments.
I have the two views but I can't manage to link them. I tried with elements, but it seems it doesn't render the view for the add comment view.
What should I do?
Thank you very much!
EDIT
Code in element:
<?php echo $this->Form->create('Comment', array('class' => 'big', 'url' => array('controller' => 'comments', 'action' => 'add', $news_id)));?>
<?php
echo $this->Form->input('comment', array('label' => false));
?>
Form->end(__('Submit', true));?>
Code in view:
<?php echo $this->element('add_comment', array('news_id' => $news['News']['id'])); ?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将代码从您的视图移动到一个元素中,然后在各处调用该元素。
move the code from your view into an element and then call the element all over the place.