Embedding view in another view with CakePHP

2019-05-22 20:17发布

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

1条回答
姐就是有狂的资本
2楼-- · 2019-05-22 20:28

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

查看更多
登录 后发表回答