您可以使用插件,这就是我所做的:
<?php
class Mobile_Layout_Controller_Plugin_Layout extends Zend_Layout_Controller_Plugin_Layout
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
switch ($request->getModuleName()) {
case 'mobile': $this->_moduleChange('mobile');
}
}
protected function _moduleChange($moduleName) {
$this->getLayout()->setLayoutPath(
dirname(dirname(
$this->getLayout()->getLayoutPath()
))
. DIRECTORY_SEPARATOR . 'layouts/scripts/' . $moduleName
);
$this->getLayout()->setLayout($moduleName);
}
}
我把它保存在library/ProjectName/Layout/Controller/Plugin/Layout.php
.
在您的 Bootsrap 中,您需要合并以下内容:
Zend_Layout::startMvc(
array(
'layoutPath' => self::$root . '/application/views/layouts/scripts',
'layout' => 'layout',
'pluginClass' => 'Mobile_Layout_Controller_Plugin_Layout'
)
);
实际上,我花了一段时间才弄清楚这一点,但是一旦你完成了它,你会更快乐。希望有帮助:)