How do you implement composite views in Zend?
I was wondering - how does one go about implementing composite views in Zend. That is, can I have multiple views and controllers on one page? I know that you can use layouts and inject the content of one controller into the layout, but is there anyway to inject multiple controlle开发者_如何学JAVArs into a particular layout?
Thanks in advance.
I don't think that you can use multiple controllers in a single layout, someone with more experience may correct me on this.
I cannot see any reason why you would want to though!
You can add either partial views using the $this->partial()
view helper or add your own view helper to add content to your layout. There is no reason why you can't access models directly in your views if required as long as they are only reading the data for display purposes. I have implemented side bars, login forms and navigation menus this way with no problems.
I hope this helps.
Kind Regards
Garry
TestController.php
public function testAction()
{
$this-view->test = 'hi';
}
test.phtml
<?php
echo $this->test;
?>
layout.phtml
$this->layout()->test = $this->action('testAction','TestController')
echo $this->layout()->test;
For more information please check Apress.Pro.Zend.Framework.Techniques.Build.a.Full.CMS.Project
精彩评论