首页 文章

zend框架布局

提问于
浏览
0

根据Rob Allen's tutorial:在我的zend应用程序中使用布局我应该:

$response = $this->getResponse();
$response->insert('header', $this->view->render('header.phtml')); 
$response->insert('sidebar', $this->view->render('sidebar.phtml')); 
$response->insert('footer', $this->view->render('footer.phtml'));

进入IndexController的init()函数,为每个动作生成页眉,页脚和侧边栏 . 我想对我的所有视图使用相同的布局,我应该将这部分代码放入所有控制器吗? (我使用的是ZF 1.11)

谢谢 .

4 回答

  • 0

    您可以通过在引导程序中执行以下操作来初始化zend布局:

    Zend_Layout::startMvc();
    

    您还可以指定保持布局的位置

    $layout = Zend_Layout::getMvcInstance();
    $layout->setLayoutPath(__PATH_TO_LAYOUT_FOLDER_);
    

    一旦到位,它将比在所有控制器中渲染相同的视图更有效 .

  • 1

    您所指的博客文章已有近5年的历史,并且绝不代表ZF 1.11的当前状态,您应该使用official Zend_Layout documentationRobs ZF1 tutorial

  • 1

    您需要布局默认值 . 您可以在模板布局中调用它 . Zend Framework文档更好地展示了它:http://framework.zend.com/manual/en/zend.layout.quickstart.html

  • 0

    到目前为止,它更容易呈现 . 在你的 application.ini 中添加此行

    resources.layout.layoutPath = APPLICATION_PATH "/layouts/scripts/" ,此路径的默认布局将命名为 layout.phtml .

    如果要更改路径或默认布局,可能需要在 application.ini 中使用两行

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

    在这种情况下,默认布局为 master.phtml .

    从默认布局更改为备用布局就像添加:

    public function preDispatch() {
    
            $this->_helper->layout->setLayout('admin');
        }
    

    对于需要新布局的控制器,可以添加逻辑,以便备用布局仅应用于某些操作 .

相关问题