Zend 导航 renderMenu 视图中
我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以从ini中删除resources.view,其效果与引导程序中的空initView()相同:视图不会被引导
我想我已经猜到发生了什么。你在哪里配置导航?
upd:为什么要使用如此奇怪的方式来获取视图实例?
您的方法,请将其替换为添加
如果您希望在 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?
replace your method with
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