0
votes

I just noticed a problem with my menu. I'm working on a php application, with Zend Framework. It looks like an empty text line is inserted in my menu and I don't understand why. For example ... Menu with empty space

As you can see, an empty space is between elements I added manually and elements generated with my menu.phtml. Here's my code ...

First, because I have 3 different menus, I saved them in Zend_Register, in my bootstrap, but I'll just show you the code for my anonymous menu.

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

        //Init du menu anonyme
        $config = new Zend_Config_Xml(APPLICATION_PATH . '/configs/navigation.xml', 'menuNotLogged');    
        $container = new Zend_Navigation($config);
        Zend_Registry::set('main',$container);
        $view->navigation($container);}

Then, in my layout I display my menu ...

<div id="navigation">
<ul id="primary-links">
<li id="overview"><a href="#">Overview test</a></li>
<li><a href="#">Manual test</a></li>
<?php
$partial = array('menu.phtml', 'default');
$this->navigation()->menu()->setPartial($partial);          

    echo $this->navigation()->menu()->render(Zend_Registry::get('main'));
?>
</ul>
</div>

Now my menu.phtml ...

foreach ($this->container as $page) {
    if ($page->isVisible()) {
        if ($page->isActive(true)) {
        //... not active so it doesn't enter here
        } else {
               echo '<li>'.$this->navigation()->menu()->htmlify($page). '</li>' ;
        }
    }
}

I tried to debug my menu in Firebug(FF) and Developer Tools(IE8), it shows empty text in the menu like that (First image is IE, second is Firefox)
Empty text odeenter image description here

There is an empty item and I can't see where it come from! I noticed it because I need to change the template of my application, and with the old menu it did the same thing, but I didn't see it, now it's really ... visible.

It really seems to be a problem when I render my menu, because if I add elements manually, there is no problem. Looking at my code, do you have any idea of what could cause that ? Does someone ever had the same problem ? Do you need other parts of my code or other details ?

Thanks already !

UPDATE

This is my menuNotLogged in my navigation.xml

   <menuNotLogged>
     <home>
        <label>Home</label>
        <uri>/index</uri>
     </home>
     <login>
        <label>Login</label>
        <uri>/index/login</uri>
     </login>
</menuNotLogged>

Here is the html output as asked

<!-- NAVIGATION_BEGIN -->
<div id="ibm-navigation">
    <ul id="ibm-primary-links">
    <li id="ibm-overview"><a href="http://w3">Overview test</a></li> 
    <li><a href="http://w3">Manual test</a></li> 

<li><a href="/index">Accueil</a></li><li><a href="/index/login">Authentification</a></li>
</ul></div>

The empty line is there in my Debug Output view from Zend Studio and in Firebug too. It's probably because of this line that an empty item is added, but I don't know where it come from.

2
Is there a element in your configuration menuNotLogged without a label maybe? And why do you use partials to render your menu and not like: echo $this->navigation()->menu(Zend_Registry::get('main'))->render(); ? Could you please post the exact output HTML where the problem is I cannot really get the picture you have posted..Kees Schepers
No there's no element without label. I tried to not use partials (can't remember why I used partials anyway ... was a long time ago), but the problem still occurs. I posted the exact HTML output. If you select the line of Manual Test element, you will see there's a space at the end of the line that is not on other lines.Fanny
Not that it solves the problem I guess but why isn't there a </li> after every element?Kees Schepers
I don't know, they are there so I corrected it with output from my Debug Output view. Finally it works when I don't use partials ! I forgot a line when I tried earlier, so I tried again after removing that line and there is no more empty space. But I remembered why menu.phtml was used, I think it was for multi-level menu. It was coded by someone else before I started working on it. Will I be able to make multi level menu works without partials ? If so, it's fine like that, but if I need partials, it would be great to make it work now in case I need some.Fanny
Finally the <li> elements are not closed in IE8, IE close these tags at the end of the div. For me it's a problem because it include all my menu id my overview li and I don't want that. I guess I'll open another question if I can't make it work :P Firefox and Chrome are ok so I guess there is a wayFanny

2 Answers

1
votes

Is there a element in your configuration menuNotLogged without a label maybe? And why do you use partials to render your menu and not like: echo $this->navigation()->menu(Zend_Registry::get('main'))->render(); ? Could you please post the exact output HTML where the problem is I cannot really get the picture you have posted..

0
votes

In the generated output you got some errors:

You open 4 li-elements, but only 1 is closed. So the unwanted space may came from broken html markup?