开发者

Render one view inside another in cakephp

开发者 https://www.devze.com 2023-03-09 22:37 出处:网络
i have a comments section that gets called at 3 place in one place along with posts and at other two places solo.(comments only). Now using this as a element makes sense. But my posts are also rendere

i have a comments section that gets called at 3 place in one place along with posts and at other two places solo.(comments only). Now using this as a element makes sense. But my posts are also rendered via a element. Does it makes sense to render a element inside a开发者_如何学JAVAnother


Here is the answer:

// Render the element in /View/Elements/ajaxreturn.ctp

$this->render('/Elements/ajaxreturn');

http://book.cakephp.org/2.0/en/controllers.html


There's nothing wrong with doing this. No clashes are going to occur as the variables are scoped

http://book.cakephp.org/view/1081/Elements


Since version 2.1 you may embed one view into another by "Extending Views"

$this->extend('/Common/view');

(documentation)


Since I knew about the elements I try to use whenever I can. They help you to minimize the code repetition. It's not unusual include elements inside another.

In fact, I use the same structure in the elements directory as the views directory to organize them.


I assume that the 3 places you mention are handled by views no? So if you have a posts element and a comments element you can include the elements needs according to the view no? In one view you only use the comments element and in the other you only use both elements what do you think?

0

精彩评论

暂无评论...
验证码 换一张
取 消