Issues

ZF-7753: Zend_Rest_Route doesn't accepts 'action' for url assembling

Description

Zend_Rest_Route doesn't accepts 'action' for url assembling.

E.g.


$navi = new Zend_Navigation();
$page = Zend_Navigation_Page::factory(array('controller' => 'page',  'label'    => 'Pages');
$page2 = Zend_Navigation_Page::factory(array('controller' => 'page',  'label' => 'New page', 'action' => 'new');
$page2->setParent($page);
$navi->addPage($page);

Zend_Registry::set('Zend_Navigation', $navi);

then in the view


<?=$this->navigation()->menu(); ?>

will result into


Page Create new page

Solution: Modify the assemble() method.

In Zend_Rest_Route, line 248, add:


if(isset($params[$this->_actionKey])) {
            $action = $params[$this->_actionKey];
            if($action === $this->_defaults[$this->_actionKey]) {
                $action = '';
            } else {
                $action = '/' . $params[$this->_actionKey];
            }
        } else {
            $action = '';
        }

In Zend_Rest_Route, line 261, replace:


if (!empty($url) || $controller !== $this->_defaults[$this->_controllerKey]) {
                $url = '/' . $controller . $url;
}

with


$url = '/' . $controller . $action . $url;

Comments

Much elegant solution.

Now it's really elegant solution.

You need to specify the route with your pages:


page2 = Zend_Navigation_Page::factory(array('route' => 'routeName', 'controller' => 'page',  'label' => 'New page', 'action' => 'new');

and then it should work. I've had success with this approach using the actions "index", "get", "post", "put", and "delete"; I haven't tried "edit" or "new", but both should work.

My application uses Zend_Rest_Route as default router. I don't think its because of undefined route name in Zend_Navigation_Page initialization.

Matthew, i checked that - solution you provided not working.

Found a solution for issue ZF-7760. Please check.

  1. Are you absolutely sure you're using a REST route?
  2. Have you tried specifying the route in the page, as Matthew suggests?
  3. If none of the two above work out for you, could you provde minimum code required to reproduce the bug?

sorry for the hiatus everyone. busy having a baby. ;)

is this still an issue? reading the comment backlog, I can't tell if Matthew's solution worked or not, and I've never used Zend_Navigation. can someone write a test case that replicates the way Zend_Navigation could/should use the route for pagination url's?

thanks.

It's been a few weeks now, so I guess this is not an issue anymore.

Alex: Could you provide a reproducable case?

So, after having a hard time to reproduce the behavior I was totally unable to. The code I used:

<?php
error_reporting(E_ALL|E_STRICT);

require_once 'Zend/Navigation.php';
require_once 'Zend/View.php';
require_once 'Zend/Navigation/Page.php';
require_once 'Zend/View/Helper/Navigation.php';
require_once 'Zend/Controller/Front.php';
require_once 'Zend/Controller/Request/Http.php';

Zend_Controller_Front::getInstance()->getRouter()->addDefaultRoutes();
Zend_Controller_Front::getInstance()->setRequest('Zend_Controller_Request_Http');

$navi = new Zend_Navigation();
$page = Zend_Navigation_Page::factory(array('controller' => 'page',  'label'    => 'Pages'));
$page2 = Zend_Navigation_Page::factory(array('controller' => 'page',  'label' => 'New page', 'action' => '$
$page2->setParent($page);
$navi->addPage($page);

$helper = new Zend_View_Helper_Navigation();
$helper->setView(new Zend_View());

echo $helper->menu($navi);

Therefore closing this issue as cannot reproduce. A next time you create an issue, please make sure to include all relevant code, preferably in a way it can be tested in cli mode. Furthermore it's unclear what the expected outcome of your code is, making it all totally vague.

Thanks Dolf.

Hi Dolf, I think I'm experiencing the same issue. In your test you're not adding a REST route. Wouldn't that be why you can't reproduce the issue?

Ah! My issue was slightly different - I was using post action in nav conf. Now I understand more about how REST routing works in Zend Framework, I've figured it out. There doesn't appear to be an issue here. As Matthew said it might be a problem by not declaring routes in nav conf.