2

I am using Twitter Bootstrap on a project and their navigation system is quite awesome. The issue is that I need Zend_Navigation to set the UL class on submenus and Im not able to achieve that.

I have a plugin that on postDispache do this:

$layout = Zend_Layout::getMVCInstance();
$view = $layout->getView();////
$view->navigation( $this->getMenu() );             // load the menu container
$view->navigation()->menu()->setUlClass('nav');    // set UL class

my code for the navigation container is:

private function getMenu()
{
    return new Zend_Navigation(array(
        array(
            'label' => 'DASHBOARD',
            'id' => 'dashboard',
            'route' => 'default_index_index',
            'class' => 'nav',
            'ulClass' => 'nav'
        ),
        array(
            'label' => 'POLICIES',
            'id' => 'policies',
            'route' => 'policies_policies_list',
            'class' => 'active nav',
            'ulClass' => 'nav',
            'pages' => array(
                array(
                    'label' => 'LIST',
                    'id' => 'policiesList',
                    'route' => 'policies_policies_add',
                    'class' => 'nav',
                    'ulClass' => 'nav'
                )
            )
        )
    ));
}       

The result code HTML is bellow:

<ul class="nav">
    <li class="active">
        <a id="menu-dashboard" class="nav" href="/">Dashboard</a>
    </li>
    <li>
        <a id="menu-policies" class="active nav" href="/policies/list">Apólices</a>
        <ul>  <!-- we should have a class nav here too -->
            <li>
                <a id="menu-policiesList" class="nav" href="/policies/add">Listar</a>
            </li>
        </ul>
    </li>
</ul>   

I know that some duplicated class stuff in the array, but I tried everything, the result is that only the FIRST UL has a class, the submenus UL's haven't. Anyone knows how I can make Zend Navigation to set the class for UL on the submenus?

Cheers

Hugo

1 Answers1

1

After a lot of search, I came a cross with a mmoussa implementation of a View Helper that overrides the menu method and implements the Twitter Bootstrap classes on the HTML.

Works like a charm. A word of advise, the menu root options shouldn't have a link for the system work correctly, should point to #.

You may download it from Git here https://github.com/mmoussa/zf1-navigation-view-helper-bootstrap

Happy coding!

Cheers,

Hugo