我有一个布局文件,如下所示:使用控制器插件来扩展Zend框架的现有布局
<?php echo $this->doctype(); ?>
<html>
<head>
<?php echo $this->headTitle(); ?>
<?php echo $this->headLink(); ?>
</head>
<body>
<?php echo $this->layout()->content; ?>
</body>
</html>
我这是写在另一个模板
<p>
<div>
menu code goes here
</div>
<p>
<?php echo $this->actionContent; ?>
</p>
</p>
我想要的菜单系统操作方法的输出应该放置在$ this-> actionContent中,所有这些都应该转到布局。
然后我写了一个控制器插件如下:
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);
}
}
}
在控制器类
class IndexController extends Zend_Controller_Action {
public function indexAction() {
}
public function viewAction()
{
$this->getRequest()->setParam('menu', false);
}
}
故取其动作不想要的菜单出现,我们可以传递参数“菜单”,值为'假'。
我的问题是:这是正确的方法吗?
您可以使用Zend的导航做 – Shaolin 2013-02-21 18:06:08