Zend framework Zend框架中的Zend_导航问题获取菜单以显示

Zend framework Zend框架中的Zend_导航问题获取菜单以显示,zend-framework,zend-navigation,Zend Framework,Zend Navigation,我有以下问题,使用zend framework,特别是zend_nav创建一个可重用菜单,通过layout/layout.phtml页面传入。这些是各自文件中的代码片段 首先,在application/configs/navigation.xml中 <configdata> <nav> <label>Home</label> <controller>index</contro

我有以下问题,使用zend framework,特别是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>
最后,在view 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>

Zend博客!
给我写博客!

然而,当我在浏览器中启动我的应用程序时,菜单没有显示出来,任何关于可能出错的想法都会被谦恭地接受。

如果您没有故意用两个
\uu
下划线命名函数
\uInitNavigation
,那么您可能期望代码自动运行。要使其自动运行,您需要使用一个下划线

另一个可能的问题是当Zend按字母顺序浏览这些资源时,
\u initNavigation
\u initView
之前运行。但是您不需要在此代码中访问
$view
。您可以使用Zend_注册表存储导航容器:

protected function _initNavigation() {
    $config = new Zend_Config_Xml(APPLICATION .'/config/navigation.xml', 'nav');
    $container = new Zend_Navigation($config);
    Zend_Registry::set('Zend_Navigation', $container);
}

当没有指定容器时,
Zend\u Navigation
注册表项将默认由任何导航助手使用。

我认为您的代码是正确的,只是受保护的函数
\u initNavigation()
\u initNavigation()


然后将
\uu initNavigation()
更改为
\u initNavigation()
好吧,我印象深刻,答案很快,这个问题有几个方面,首先你们都正确地使用了一个下划线符号,非常感谢你们! 结果我确实拼错了

$config = new Zend_Config_Xml(APPLICATION .'/config/navigation.xml', 'nav');
应该是,

$config = new Zend_Config_Xml(APPLICATION_PATH .'/configs/navigation.xml', 'nav');
是我的错。最后,在navigation.xml文件中,在-node内,每个“页面”节点周围都应该有节点,例如home。它应该有

   <configdata>
     <nav> 
      <home>     
       <label>Home</label>
        <controller>index</controller>
        <action>index</action>
      </home>

家
指数
指数
就这样

再次感谢你的提示和提示,我知道正确的方向

辛克·卡勒·约翰逊

   <configdata>
     <nav> 
      <home>     
       <label>Home</label>
        <controller>index</controller>
        <action>index</action>
      </home>