0

With zend framework how do i create a single level menu?

I followed a tutorial and the person created a two level dropdown menu. I want to just remove home. I've modified the navigation.xml file a couple times and it caused a fatal error.

What xml markup do i need to promote the children of home as the parent level menus? As in i don't need a home button at all.

Desired outcome:

  • who
  • why
  • what
  • speaker
  • resources

Current outcome:

  • home

    • who

    • what

    • when

    • why

Current navigation.xml file:

<?xml version="1.0" encoding="UTF-8" ?>
<configdata>
  <nav>
    <home>
      <label>Home</label>
      <controller>page</controller>
      <action>index</action>
      <module>default</module>
      <pages>
        <why>
          <label>why</label>
          <controller>page</controller>
          <action>why</action>
          <module>default</module>
        </why>
        <who>
          <label>who</label>
          <controller>page</controller>
          <action>who</action>
        </who>
        <resources>
          <label>resources</label>
          <controller>page</controller>
          <action>resources</action>
        </resources>
        <signin>
          <label>sign in</label>
          <controller>account</controller>
          <action>login</action>
          <module>default</module>
        </signin>
      </pages>
    </home>
  </nav>

...

application/Bootstrap.php:

<?php function _initViewHelpers() {
   $this->bootstrap('layout);
   // ... Skipping to relevant part
    $navContainerConfig = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'nav');
    $navContainer = new Zend_Navigation($navContainerConfig);
    $view->navigation($navContainer);
} ?>

layouts/default.phtml

<div class="navigation"><?php print $this->navigation(); ?></div>
1
  • Can you provide us some code about how you render the navigation? Commented Apr 20, 2012 at 4:08

4 Answers 4

1
<?xml version="1.0" encoding="UTF-8" ?>
<configdata>
  <nav>
     <why>
      <label>why</label>
      <controller>page</controller>
      <action>why</action>
      <module>default</module>
    </why>
    <who>
      <label>who</label>
      <controller>page</controller>
      <action>who</action>
    </who>
    <resources>
      <label>resources</label>
      <controller>page</controller>
      <action>resources</action>
    </resources>
    <signin>
      <label>sign in</label>
      <controller>account</controller>
      <action>login</action>
      <module>default</module>
    </signin>
 </nav>
Sign up to request clarification or add additional context in comments.

Comments

1

What about setMaxDepth() and setMinDepth()? You can set how deep you want your menu to be rendered:

<?= $this->navigation()->menu()
                       ->setMinDepth(1)
                       ->setMaxDepth(2)
                       ->render() . PHP_EOL; ?>

Also, you can find more information about the navigation view helper in the official manual. These information are often more relevant than the ones you can find in tutorials.

Comments

1

you should be able to just adjust your container to display only the links you want displayed. In this case you would just remove the Home elements from your xml file.

<?xml version="1.0" encoding="UTF-8" ?>
<configdata>
  <nav>
      <pages>
        <why>
          <label>why</label>
          <controller>page</controller>
          <action>why</action>
          <module>default</module>
        </why>
        <who>
          <label>who</label>
          <controller>page</controller>
          <action>who</action>
        </who>
        <resources>
          <label>resources</label>
          <controller>page</controller>
          <action>resources</action>
        </resources>
        <signin>
          <label>sign in</label>
          <controller>account</controller>
          <action>login</action>
          <module>default</module>
        </signin>
      </pages>
  </nav>

Comments

0

When you remove the Home menu from the XML file , you get an exception

Zend_Navigation_Exception: Invalid argument: Unable to determine class to instantiate in C:\www\project\library\Zend\Navigation\Page.php on line 235

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.