zend-framework - 如何在 Zend Framework 中设置多个布局。例如。公开/登录/多种模块组合

标签 zend-framework zend-view zend-layout

我知道并使用了非常基本的 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/

相关文章:

mysql - 将 FORCE INDEX 与 zend 结合使用

model-view-controller - Zend_Form 在 Model View Controller 范式中的位置

php - 带有 JavaScript 库的 Zend 框架

php - zend_form ViewScript 装饰器/传递参数

php - ZFTool : Module (ZFTool) could not be initialized 问题

php - catch 语句中函数的错误处理

zend-framework - 我可以在 Zend Framework 中有多个布局吗?

zend-framework - Adobe Reader 无法打开在 Zend Framework 中使用 mPDF 创建的 .pdf 文件

php - 如何将自定义 View 助手添加到 Zend Framework 2

php - Zend Framework - 为 Controller 设置无布局