{
public function preDispatch()
{
$bootstrap = $this->getActionController()
->getInvokeArg('bootstrap');
$config = $bootstrap->getOptions();
$module = $this->getRequest()->getModuleName();
if (isset($config[$module]['resources']['layout']['layoutPath'])) {
$layoutPath =
$config[$module]['resources']['layout']['layoutPath'];
$this->getActionController()
->getHelper('layout')
->setLayoutPath($layoutPath);
}
}
}
接下来我们还需要将它添加到application/Bootstrap.php里去
protected function _initLayoutHelper()
{
$this->bootstrap('frontController');
$layout = Zend_Controller_Action_HelperBroker::addHelper(
new Rockux_Controller_Action_Helper_LayoutLoader());
}
再次访问http://localhost/admin,应当就可以看到使用指定的布局文件了。
如果要针对某个特定的controller使用特定的layout,可以在controller的init()方法里添加如下代码:
$layout = Zend_Layout::getMvcInstance();
$layout->setLayout('layout_special');







