I have a layout file as follows:
<?php echo $this->doctype(); ?>
<html>
<head>
<?php echo $this->headTitle(); ?>
<?php echo $this->headLink(); ?>
</head>
<body>
<?php echo $this->layout()->content; ?>
</body>
</html>
I have a menu system which is written in another template
<p>
<div>
menu code goes here
</div>
<p>
<?php echo $this->actionContent; ?>
</p>
</p>
I wanted the action method's output should be placed in $this->actionContent and all of that should go to the layout.
Then I wrote a Controller plugin as follows:
class ZFExt_Controller_Plugin_Addmenu extends Zend_Controller_Plugin_Abstract
{
public function postDispatch(Zend_Controller_Request_Abstract $request)
{
$view = Zend_Controller_Front::getInstance()
->getParam('bootstrap')
->getResource('view');
if (false !== $request->getParam('menu'))
{
$response = $this->getResponse();
$content = $response->getBody(true);
$view->menuContent = $content['default'];
$updatedContent = $view->render('menu.phtml');
$response->setBody($updatedContent);
}
}
}
In the controller class
class IndexController extends Zend_Controller_Action {
public function indexAction() {
}
public function viewAction()
{
$this->getRequest()->setParam('menu', false);
}
}
So whichever action does not want the menu there we can pass a parameter 'menu' with value 'false'.
My question is: Is this the right way to do ?