本文介绍了Zend Framework中可以有多个布局吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的页面很华丽,前端有图像旋转器.
I have a flashy page with image rotators in the front end for the clients.
对于后端,我希望具有不同的布局.我可以有多种布局吗?
For back-end I want to have different layout. Can i have multiple layout?
一些提示会很有意义
推荐答案
我创建一个布局插件,以在调用非默认模块时切换布局:
I create a layout plugin, to switch layouts when a non-default module is called:
class MyApplication_Layout_Controller_Plugin_Layout extends Zend_Layout_Controller_Plugin_Layout
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
switch ($request->getModuleName()) {
case 'admin': $this->_moduleChange('admin');
}
}
protected function _moduleChange($moduleName) {
$this->getLayout()->setLayoutPath(
dirname(dirname(
$this->getLayout()->getLayoutPath()
))
. DIRECTORY_SEPARATOR . 'layouts/scripts/' . $moduleName
);
$this->getLayout()->setLayout($moduleName);
}
}
然后在我的Bootstrap中,我这样做:
Then in my Bootstrap, I do this:
Zend_Layout::startMvc(
array(
'layoutPath' => self::$root . '/application/views/layouts/scripts',
'layout' => 'layout',
'pluginClass' => 'MyApplication_Layout_Controller_Plugin_Layout'
)
);
非默认布局位于以模块命名的文件夹内,因此我的目录结构如下:
The non-default layouts go inside a folder named after the module, so my directory structure looks like this:
/path/to/application/views/layouts/scripts/layout.phtml --> default layout
/path/to/application/views/layouts/scripts/admin/admin.phtml --> admin layout
这篇关于Zend Framework中可以有多个布局吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!