Zend 导航 renderMenu 视图中

发布于 2024-10-21 14:24:40 字数 1096 浏览 2 评论 0原文

我正在使用 Zend Navigation 创建菜单。当我在布局脚本中使用 $this->navigation( ) 时,菜单会完美呈现。但是,当我尝试在视图脚本中使用相同的代码渲染相同的菜单时,不会渲染任何内容。

这是我在引导程序中用于启动 Zend_Navigation 并将其附加到布局脚本的代码:

protected function _initNavigation( )
{
    $this->bootstrap( 'layout' );
    $layout = $this->getResource( 'layout' );

    $view = $layout->getView( );
    $config = new Zend_Config_Xml( APPLICATION_PATH . '/configs/navigation.xml', 'nav' );
    $navigation = new Zend_Navigation( $config );

    $view->navigation( $navigation );
    $view->addHelperPath( 'App/View/Helper/Navigation', 'App_View_Helper' );
}

我已经研究这个问题一段时间了,并发现我需要将以下代码添加到我的引导程序中:

protected function initView( ) { }

但是我'我想知道为什么我需要放置这段无用的代码。根据 this 主题,我已经引导了视图我的 application.ini 中的资源,使用以下行:

resources.view.basePath = APPLICATION_PATH "/views"
resources.view.helperPath = APPLICATION_PATH "/views/helpers"

提前致谢!

I'm using Zend Navigation to create my menus. When I use $this->navigation( ) in my layout script, the menu gets rendered perfectly. But when I try to render the same menu with the same code in a view script, nothing gets rendered.

This is the code I use in the bootstrap to initiate Zend_Navigation and attach it to the layout script:

protected function _initNavigation( )
{
    $this->bootstrap( 'layout' );
    $layout = $this->getResource( 'layout' );

    $view = $layout->getView( );
    $config = new Zend_Config_Xml( APPLICATION_PATH . '/configs/navigation.xml', 'nav' );
    $navigation = new Zend_Navigation( $config );

    $view->navigation( $navigation );
    $view->addHelperPath( 'App/View/Helper/Navigation', 'App_View_Helper' );
}

I've been working on this problem for a while, and figured out that I needed to add the following code to my bootstrap:

protected function initView( ) { }

But I'm wondering why I need to place this useless piece of code. According to this topic, I already bootstrap the view resource in my application.ini, by using the following lines:

resources.view.basePath = APPLICATION_PATH "/views"
resources.view.helperPath = APPLICATION_PATH "/views/helpers"

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

揽清风入怀 2024-10-28 14:24:40

您可以从ini中删除resources.view,其效果与引导程序中的空initView()相同:视图不会被引导

我想我已经猜到发生了什么。你在哪里配置导航?

upd:为什么要使用如此奇怪的方式来获取视图实例?

protected function _initNavigation( )
{
    $this->bootstrap( 'view' );
    $view = $this->getResource( 'view' );
    ///...
}

您的方法,请将其替换为添加

protected function _initNavigationPages( )
{
    $this->bootstrap( 'navigation' );
    $navigation = $this->getResource( 'navigation' );

    $config = new Zend_Config_Xml( APPLICATION_PATH . '/configs/navigation.xml', 'nav' );
    $navigation->addPages($config);
}

如果您希望在 Zend_Registry 中的“Zend_Navigation”键或“resources.navigation[] =”下注册 到配置“resources.navigation.storage.registry = true”存储在视图助手中

视图助手路径/前缀设置移动到视图配置

you can remove resources.view from ini with same effect as with empty initView() in bootstrap: view will not be bootstrapped

i think i have guess what is going on. where are you configure your navigation?

upd: Why do you using such a strange way to get view instance?

protected function _initNavigation( )
{
    $this->bootstrap( 'view' );
    $view = $this->getResource( 'view' );
    ///...
}

replace your method with

protected function _initNavigationPages( )
{
    $this->bootstrap( 'navigation' );
    $navigation = $this->getResource( 'navigation' );

    $config = new Zend_Config_Xml( APPLICATION_PATH . '/configs/navigation.xml', 'nav' );
    $navigation->addPages($config);
}

add to config "resources.navigation.storage.registry = true" if you want it to be registered in Zend_Registry under 'Zend_Navigation' key or "resources.navigation[] =" to store in view helper

view helper path/prefix setup move to view configuraton

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文