【问题标题】:Bootstrapping Zend Layout and include navigation resource引导 Zend 布局并包含导航资源
【发布时间】:2011-06-12 11:02:55
【问题描述】:

当我使用以下引导程序时,我在渲染导航菜单时遇到了问题:

public function _initViewHelpers()
{
    $this->bootstrap('layout');
    $layout = $this->getResource('layout');
    $view = $layout->getView(); // Never inits navigation resource?

    $view->headTitle()->setSeparator(' - ')
         ->headTitle('Test');

    $role = ($this->_auth->getStorage()->read() === null) ? 'guest' : $this->_auth->getStorage()->read()->role;
    $view->navigation()->setAcl($this->_acl)->setRole($role); 
}

在我的layout.phtml 我有:

echo $this->navigation()->menu();

在我的application.ini 我有:

resources.navigation.pages.index.label = "Home"
resources.navigation.pages.index.title = "Go Home"
resources.navigation.pages.index.controller = "index"
resources.navigation.pages.index.action = "index"
resources.navigation.pages.index.order = -100
resources.navigation.pages.index.route = "default"

发出$view = $layout->getView(); 会导致我的导航菜单未呈现。如果我把那部分注释掉,它会很好。

如何在引导程序中设置标题和 acl 角色,并且仍然正确呈现我的菜单?

【问题讨论】:

    标签: php zend-framework zend-navigation zend-acl


    【解决方案1】:

    您是否尝试将视图资源添加到您的 application.ini 并直接检索您的资源?

    application.ini:

    resources.view[] =
    

    引导程序:

    public function _initViewHelpers()
    {
        $this->bootstrap('layout');
        $this->bootstrap('view');
        $this->bootstrap('navigation');
        $layout = $this->getResource('layout');
        $view = $this->getResource('view');
        ....
    

    【讨论】:

    • 简单地引导视图就可以了:)我在$view = $layout->getView();之前添加了$this->bootstrap('view');
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-10
    • 1970-01-01
    相关资源
    最近更新 更多