2

我知道并使用了非常基本的 Zend 框架布局,我在整个站点中使用了 1 个布局。但现在我需要一个更中间/有组织的设置。

  • 公共站点布局将div#mainContent占据整个 12 列(使用 960gs)
  • 登录的站点将div#mainContent占用 9 列 + 3 列侧栏
  • 在登录站点的侧边栏中,各种页面可能包含各种模块(不是 Zend Framework 的模块,更像是“boxes/widgets”)
  • 他们也会有不同的导航菜单

我正在考虑使用 1 个基本布局,其中 2 个子布局将“扩展”。基本布局将只包含<html>声明 headScripts 等,<body>然后子布局将包含 wrapping 的定义divs div.grid_12, grid_9, grid_3。我该如何实现这个“扩展”,基本上,我只想重用代码

还有什么是渲染侧边栏框/小部件的好方法

4

2 回答 2

9

我根据我网站的子域在布局之间切换。

这是我正在使用的布局插件......

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

我希望这会有所帮助......
天使

于 2011-01-19T12:26:22.527 回答
2

我们这样做的方式是在每个控制器中可用的 init() 方法中设置当前布局,我不确定这是否是最好的方法。

例如,如果我们有这个 URL:www.mysite.com/social/

class SocialController extends BaseController
{
    public function init(){
        $layout = $this->_helper->layout();
        $layout->setLayout('social');
    }
}

然后在 config.ini 中:

resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/"

在 resources.layout.layoutPath 中定义了一个 socia.phtml

于 2011-09-07T06:35:20.853 回答