zend 框架中的 Zend_Nav 问题导致菜单显示
我有以下问题,使用 zend 框架,特别是 zend_nav 创建一个可重用的菜单,通过layout/layout.phtml 页面传入。这些是各自文件中的代码片段。
首先在 application/configs/navigation.xml 中,
<configdata>
<nav>
<label>Home</label>
<controller>index</controller>
<action>index</action>
<pages>
<add>
<label>Add</label>
<controller>post</controller>
<action>add</action>
</add>
<login>
<label>Admin</label>
<controller>login</controller>
<action>login</action>
</login>
</pages>
</nav>
</configdata>
然后将其传递到 Bootstrap.php 文件中的一个对象(仅显示该特定方法)
protected function __initNavigation(){
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Xml(APPLICATION .'/config/navigation.xml', 'nav');
$container = new Zend_Navigation($config);
$view->navigation($container);
}
,最后在视图 layout.phtml 中,该对象应返回菜单 菜单
<!-- application/layouts/scripts/layout.phtml -->
<?php echo $this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Zend Blog !</title>
<?php echo $this->headLink()->appendStylesheet('/css/global.css')?>
</head>
<body>
<div id="header">
<div id="header-logo">
<b>Blog Me !</b>
</div>
</div>
<div id="menu">
<?php echo $this->navigation()->menu() ?>
</div>
<div id="content">
<?php echo $this->layout()->content ?>
</div>
</body>
</html>
确实然而,当我在浏览器中启动我的应用程序时,它没有出现,任何关于可能出错的想法,都会虚心接受。
I have the following problem, using zend framework, specifically zend_nav to create a reusable menu to be passed in via the layout/layout.phtml page. These are the code fragments in their respective files.
first of in application/configs/navigation.xml,
<configdata>
<nav>
<label>Home</label>
<controller>index</controller>
<action>index</action>
<pages>
<add>
<label>Add</label>
<controller>post</controller>
<action>add</action>
</add>
<login>
<label>Admin</label>
<controller>login</controller>
<action>login</action>
</login>
</pages>
</nav>
</configdata>
this is then passed into an object in the Bootstrap.php file(only showing that specific method)
protected function __initNavigation(){
$this->bootstrap('layout');
$layout = $this->getResource('layout');
$view = $layout->getView();
$config = new Zend_Config_Xml(APPLICATION .'/config/navigation.xml', 'nav');
$container = new Zend_Navigation($config);
$view->navigation($container);
}
and then finally in the view layout.phtml, the object should return the menu
<!-- application/layouts/scripts/layout.phtml -->
<?php echo $this->doctype() ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Zend Blog !</title>
<?php echo $this->headLink()->appendStylesheet('/css/global.css')?>
</head>
<body>
<div id="header">
<div id="header-logo">
<b>Blog Me !</b>
</div>
</div>
<div id="menu">
<?php echo $this->navigation()->menu() ?>
</div>
<div id="content">
<?php echo $this->layout()->content ?>
</div>
</body>
</html>
The menu does however not show up when i start up my app in the browser, any ideas as to might have gone wrong, is humbly received.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您没有故意使用两个
_
下划线命名函数__initNavigation
,那么您可能希望代码自动运行。为了让它自动运行,您需要使用一个下划线。另一个可能的问题是
_initNavigation
在_initView
之前运行,因为 Zend 按字母顺序浏览这些资源。但是您不需要在此代码中访问$view
。您可以使用Zend_Registry
来存储导航容器:当未指定容器时,任何导航助手都将默认使用
Zend_Navigation
注册表项。If you did not name the function
__initNavigation
with two_
underscores on purpose then you probably expected the code to run automatically. For it to run automatically you need to use a single underscore.Another possible problem is that
_initNavigation
runs before_initView
as Zend goes through these resources in alphabetical order. But then you need not access$view
in this code. You can use theZend_Registry
to store the navigation container:The
Zend_Navigation
registry entry will be used by default by any navigation helper when no container is specified.好吧,我印象深刻,答案非常快,问题有几个方面,首先你们俩都正确地使用了单个下划线符号,非常感谢你们俩!
事实证明,我确实拼写错误,
应该是
我的错。最后,在 navigation.xml 文件中,在 - 节点内,每个“页面”节点周围都应该有节点,例如主页。应该是
这样吧!
再次,非常感谢您在正确的方向上提供的提示和技巧。
辛卡勒约翰逊
Well i`m impressed, really quick answers, the problem had several aspects, first of you where both right about using a single underscore sign, thanks a lot the both of you !
And as i t turned out, i did misspell,
should be,
my fault. And finally a miss in the navigation.xml file, inside the - node, there should be nodes surrounding each of the "page" nodes, that is for instance for the home. It should have
That was it !
Again, thanks a lot for your hints and tips i the right direction.
Sinc Kalle Johansson
我认为你的代码是正确的,只是你的受保护函数
__initNavigation()
应在
_initNavigation()
中仅使用一个_
然后将
__initNavigation()
更改为_initNavigation()
I think your code is correct, just your protected function
__initNavigation()
should use just one
_
in your_initNavigation()
Then change
__initNavigation()
to_initNavigation()