我在前端为客户提供了一个带有图像旋转器的华丽页面。
对于后端,我想要不同的布局。我可以有多个布局吗?
一点提示将是可观的
我在前端为客户提供了一个带有图像旋转器的华丽页面。
对于后端,我想要不同的布局。我可以有多个布局吗?
一点提示将是可观的
我创建了一个布局插件,用于在调用非默认模块时切换布局:
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);
}
}
然后在我的引导程序中,我这样做:
Zend_Layout::startMvc(
array(
'layoutPath' => self::$root . '/application/views/layouts/scripts',
'layout' => 'layout',
'pluginClass' => 'MyApplication_Layout_Controller_Plugin_Layout'
)
);
非默认布局位于以模块命名的文件夹中,因此我的目录结构如下所示:
/path/to/application/views/layouts/scripts/layout.phtml --> default layout
/path/to/application/views/layouts/scripts/admin/admin.phtml --> admin layout
是的,您可以拥有多个布局,尽管根据请求切换它们并不是那么简单。
我必须这样做足够多次,最终开发了一个控制器动作助手和应用程序资源插件,您可以自由使用或从中获取灵感。
尝试
//in controller
$this->_helper->layout->setLayout('layoutName');
它会将布局切换到模块视图/脚本文件夹中的 layoutName.phtml ;)
这是错误的。该行:
class MyApplication_Layout_Controller_Plugin_Layout extends end_Layout_Controller_Plugin_Layout
应该是extends Zend_Controller_Plugin_Abstract
。否则,您将收到有关mvcSuccessfulActionOnly
.