使用CakePHP在另一个视图中嵌入视图 [英] Embedding view in another view with CakePHP

查看:145
本文介绍了使用CakePHP在另一个视图中嵌入视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个新闻控制器与每个新闻项目的'视图'动作。在每个新闻项目的'视图'动作中,我想包括另一个视图,评论控制器的'添加'动作。
基本上,我需要在每个新闻项目的页面上添加一个表单来添加评论。
我有两个视图,但我不能设法链接他们。我尝试使用元素,但它似乎不会渲染添加评论视图的视图。

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.

我应该怎么办?

非常感谢!

EDIT

in element:

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));?>

Form->end(__('Submit', true));?>

代码视图:

<?php echo $this->element('add_comment', array('news_id' => $news['News']['id'])); ?>


推荐答案

将代码从视图移动到元素调用元素遍布整个地方。

move the code from your view into an element and then call the element all over the place.

这篇关于使用CakePHP在另一个视图中嵌入视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆