我知道并使用了非常基本的 Zend Framework 布局,我在整个站点中使用了一种布局。但现在我需要一个更中级/更有条理的设置。
- 公共(public)站点布局将具有
div#mainContent
占满12列(使用960gs) - 登录站点将有
div#mainContent
占9列+侧边栏3列 - 在登录站点的侧边栏中,各种页面可能包含各种模块(不是 Zend Framework 的模块,更像是“框/小部件”)
- 他们也会有不同的导航菜单
我正在考虑使用 1 个基本布局,其中 2 个子布局将“扩展”。基本布局将只包含 <html>
声明 headScripts 等直到 <body>
那么子布局将包含包装的定义 divs
div.grid_12, grid_9, grid_3
.我如何实现这个“扩展”,基本上,我只是想重用代码
还有什么是渲染侧边栏框/小部件的好方法
最佳答案
我根据网站的子域在布局之间切换。
这是我正在使用的布局插件...
class App_Layout_Controller_Plugin_Layout extends Zend_Layout_Controller_Plugin_Layout
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$layout = $this->getLayout();
$filename = $layout->getLayoutPath() . '/' . $request->getModuleName() . '.' . $layout->getViewSuffix();
//check if the layout template exists, if not use the default layout set in application.ini
if (file_exists($filename))
{
$this->getLayout()->setLayout($request->getModuleName());
}
}
}
当然你可以根据自己的需要修改它。
确保您也正确设置了 application.ini,包括如下元素...
resources.layout.layout = "default"
resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts"
resources.layout.pluginClass = "App_Layout_Controller_Plugin_Layout"
在我的例子中,我有:
default.phtml, admin.phtml, clients.phtml
我希望这对您有所帮助...
天使
关于zend-framework - 如何在 Zend Framework 中设置多个布局。例如。公开/登录/多种模块组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4732778/