1
votes

Currently i'm playing with Zend Navigation in ZF2 and i come across the following problem

in my application module i have the following config (default skeleton app)

....
'router' => array(
    'routes' => array(
        'home' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'index',
                ),
            ),
        ),
        // The following is a route to simplify getting started creating
        // new controllers and actions without needing to create a new
        // module. Simply drop new controllers in, and you can access them
        // using the path /application/:controller/:action
        'application' => array(
            'type'    => 'Literal',
            'options' => array(
                'route'    => '/application',
                'defaults' => array(
                    '__NAMESPACE__' => 'Application\Controller',
                    'controller'    => 'Index',
                    'action'        => 'index',
                ),
            ),
            'may_terminate' => true,
            'child_routes' => array(
                'default' => array(
                    'type'    => 'Segment',
                    'options' => array(
                        'route'    => '/[:controller[/:action]]',
                        'constraints' => array(
                            'controller' => '[a-zA-Z][a-zA-Z0-9_-]*',
                            'action'     => '[a-zA-Z][a-zA-Z0-9_-]*',
                        ),
                        'defaults' => array(
                        ),
                    ),
                ),
            ),
        ),
        'info' => array(
            'type' => 'Zend\Mvc\Router\Http\Literal',
            'options' => array(
                'route'    => '/phpinfo',
                'defaults' => array(
                    'controller' => 'Application\Controller\Index',
                    'action'     => 'info',
                ),
            ),
        ),
    ),
),
....
'navigation' => array(
    'default' => array(
        array(
            'label' => 'Home',
            'route' => 'home',
            'order' => -1,
            'pages' => array(
                array( //<-- this isn't working gives a link to /application
                    'label'         => 'Telefoonboek',
                    'route'         => 'application',
                    'module'        => 'application',
                    'controller'    => 'telefoonboek',
                    'action'        => 'index',
                ),
                array( //<-- this works
                    'label'         => 'Telefoonboek2',
                    'uri'           => '/application/telefoonboek', 
                ),
                array( //<-- this works
                    'label'         => 'info',
                    'route'         => 'info',
                ),
            ),
        ),

    ),
),
....

I'm currently only able to make the navigation work when i add a route for "every" item i want in the menu. But this is kind of a weird solution.

So is this the right way to make the menu work or do i need to do something fancy with the pages?

1
I actually got it to work myself :) instead of using the parent (application) route i needed to point it to the child route application/default problem solvedPonsjuh
Post it as answer ;) For faster references to other users.Sam

1 Answers

2
votes

I actually got it to work myself :) instead of using the parent (application) route i needed to point it to the child route application/default problem solved

so the config now looks like

   ....
'navigation' => array(
    'default' => array(
        array(
            'label' => 'Home',
            'route' => 'home',
            'order' => -1,
            'pages' => array(
                array( //<-- this NOW works too
                    'label'         => 'Telefoonboek',
                    'route'         => 'application/default',
                    'controller'    => 'telefoonboek',
                    'action'        => 'index',
                ),
                array( //<-- this works
                    'label'         => 'Telefoonboek2',
                    'uri'           => '/application/telefoonboek', 
                ),
                array( //<-- this works
                    'label'         => 'info',
                    'route'         => 'info',
                ),
            ),
        ),

    ),
),
....