Issue

ZF-6486: Using Zend_Navigation combined with a route href problem

Issue Type: Bug Created: 2009-05-01T11:55:52.000+0000 Last Updated: 2011-04-05T07:39:32.000+0000 Status: Resolved Fix version(s): Reporter: Deleted (cmodijk) Assignee: Robin Skoglund (robinsk) Tags: - Zend_Controller

  • Zend_Navigation

Related issues: - ZF-11261

Attachments:

Description

I'm using the Zend_Navigation to build a menu, this is build in the bootstrap file. One of the pages go's to a route, when i'm in that routed page al href's of the pages into my menu go's to that route and not the right module / controller / view..

Here's the code

<pre class="highlight">
$pages = array(
    array(
        'label' => 'Company',
        'title' => 'About us',
        'module' => 'newmodule',
        'controller' => 'index',
        'action' => 'index',
        'pages' => array(
            array(
                'label' => 'News',
                'class' => 'rss', // class
                'module' => 'newmodule',
                'controller' => 'index',
                'action' => 'index',
                'pages' => array(
                    array(
                        'label' => 'Archive',
                        'route' => 'blaat', // route
                        'module' => 'newmodule',
                        'controller' => 'index',
                        'action' => 'hallow',
                        'params' =>array("year"=>"2009")
                    )
                )
            )
        )
    ),
);
$view->navigation()->addPages($pages);


$router = $frontController->getRouter();
$router->addDefaultRoutes();
$router->addRoute(
    'blaat',
    new Zend_Controller_Router_Route(
        '/archive/:year',
        array(
            'module' => 'newmodule',
            'controller' => 'index',
            'action' => 'hallow',
            'year' => (int) date('Y') - 1
        ),
        array('year' => '\d+')
    )
);

Comments

Posted by Deleted (cmodijk) on 2009-05-01T12:14:39.000+0000

I have the problem with the $this->navigation()->menu(); function When I first call $page1->getHref(); and then the menu function the problem don't appears

Posted by Robin Skoglund (robinsk) on 2009-05-01T12:16:55.000+0000

This is probably because you haven't specified any route for the other pages. If I recall correctly, the Zend_Controller_Action_Helper_Url (which the component uses to generate URLs) will use the currently active route if null is given as $route in the call to $helper->url($params, $route, ...).

Does it work as expected if you specify 'default' as module for the other pages?

Posted by Deleted (cmodijk) on 2009-05-01T12:46:47.000+0000

Yes this work's thanks!

But... It is a little strange because the code I uses is from the documentation @ http://framework.zend.com/manual/en/…

Maybe it's a idee if the 'route' is not specified the value automatic is default?

Posted by Robin Skoglund (robinsk) on 2009-05-01T12:57:53.000+0000

That was the case originally, but it was changed to null because many users reported that they did not use the 'default' route, or changed it to something else.

I'll try and add a note about this in the manual for the next mini release.

Posted by Deleted (cmodijk) on 2009-05-01T13:16:44.000+0000

Oke, thank you for this information

Posted by Igor Fridman (igorsf) on 2009-09-20T12:18:26.000+0000

I have exactly the same problem. Why is this "Not an Issue"? Can someone please explain?

Posted by Robin Skoglund (robinsk) on 2009-09-20T12:44:19.000+0000

Because this is the way the routing system works. If you don't specify a route to the URL helper (which uses router's assemble() method), it will use assume the currently active route should be used for assembling the URL.

As a concequence of this -- if you use more than one module in your application -- you have to specify which route each page in Zend_Navigation should be using, because it has no way of knowing itself.

In the earliest versions of Zend_Navigation (when it was still Zym_Navigation), pages used 'default' as a default route. This "solved" the issue described here, but it causes problems for people not using a default route, or has a default route that is not named 'default'. That's why the default route was dropped from pages in Zend_Navigation, to be true to the ZF spirit of not imposing restrictions or lay assumptions on application structure.

Hope this helped clarify. If not, just ask. It should also be said that I do see how it would be useful to have the default route specified, since it would mean less configuration. This is something we have to discuss in the community, and get feedback from the zenders (Matthew).

Posted by Igor Fridman (igorsf) on 2009-09-20T12:59:32.000+0000

Specifing default for all the other pages worked for me. What is the difference between null and 'default' route and why Zend_Controller_Action_Helper_Url uses the currently active route?

Posted by Robin Skoglund (robinsk) on 2009-09-20T13:02:28.000+0000

null means "use the currently active route" 'default' means "use the actual route instance named 'default'"

...as it should be, really.

Posted by Igor Fridman (igorsf) on 2009-09-20T13:18:50.000+0000

Thanks for answering my questions. It would be very useful to add a note under "Example 37.4. Using routes" describing this issue. http://framework.zend.com/manual/en/…

Posted by Vlatko Basic (vlatkobasic) on 2009-11-19T01:43:03.000+0000

I don't think it is a good idea to change the behavior so much. There should have been made a solution to specify a "default" route. This way, neither the "Default" route can be used without much configuration, neither some other differently named default route.

Here is a simple solution that reverts the old behavior, for "menu" and "url" helpers.

<pre class="highlight">
class Old_Controller_Router_Rewrite extends Zend_Controller_Router_Rewrite {

  public function assemble($userParams,$name=null,$reset=false,$encode=true){
    if ($name == null) {
      $name = 'default';
    }
    return parent::assemble($userParams, $name, $reset, $encode);
  }

}

Something similar should be done in next ZF release (before 2.0 :-) )

Have you found an issue?

See the Overview section for more details.

Copyright

© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.

Contacts