如何在Zend Framework中设置多个布局.例如.公共/已登录/各种模块组合 [英] How to setup multiple Layouts in Zend Framework. Eg. Public/Logged in/Various combinations of modules
问题描述
我知道&使用了非常基本的Zend Framework的Layouts,在整个站点中我使用了1种布局.但是现在我需要一个更中间/更有组织的设置.
I know & used the very basic Zend Framework's Layouts where I used 1 layout throughout the whole site. But now I need a more intermediate/organized setup.
- 公共站点布局中的
div#mainContent
将占据全部12列(使用960gs) - 登录的站点将包含
div#mainContent
占据9列+带有3列的侧栏 - 在已登录站点的侧边栏中,各个页面可能包含各种模块(不是Zend Framework的模块,更像是盒子/小部件")
- 它们也将具有不同的导航菜单
- The public site layout will have the
div#mainContent
taking up the whole 12 columns (using 960gs) - The logged in site will have
div#mainContent
taking up 9 columns + side bar with 3 columns - In the sidebar of the logged in site, various pages may contain various modules (not Zend Framework's modules, more like "boxes/widgets")
- They will have different nav menus too
我正在考虑使用1个基本布局,其中2个子布局将扩展".基本布局将只包含<html>
声明的headScripts等,直到<body>
为止,然后子布局将包含包装divs
div.grid_12, grid_9, grid_3
的定义.我该如何实现这种扩展",基本上,我只想重用代码
I am thinking of using 1 base layout where the 2 sub layouts will "extend". The base layout will just contain the <html>
declarations headScripts etc till the <body>
then the sublayouts will contain definations for the wrapping divs
div.grid_12, grid_9, grid_3
. How can I implement this "extending", basically, I just want to reuse code
还有什么是呈现侧边栏框/小工具的好方法
Also whats a good way to render sidebar boxes/widgets
推荐答案
我正在根据我的网站的子域在布局之间进行切换.
I'm switching between layouts depending on the subdomain of my website.
这是我正在使用的布局插件...
Here's the layout plugin I'm using...
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());
}
}
}
当然,您可以根据自己的需要进行修改.
Of course you can modify this for your own needs.
确保您也正确设置了application.ini,其中包括如下内容...
Make sure you set up you application.ini correctly too including elements like the following...
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
default.phtml, admin.phtml, clients.phtml
我希望这对您有帮助...
天使
I hope this helps...
Angel
这篇关于如何在Zend Framework中设置多个布局.例如.公共/已登录/各种模块组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!