Issue Type: Patch Created: 2009-09-02T03:35:52.000+0000 Last Updated: 2011-01-29T19:42:01.000+0000 Status: Resolved Fix version(s): Reporter: Alex Zinchenko (admloki) Assignee: Dolf Schimmel (Freeaqingme) (freak) Tags: - Zend_Navigation
Related issues: Attachments: - zend_rest_route.diff
Zend_Rest_Route doesn't accepts 'action' for url assembling.
E.g.
<pre class="highlight">
$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
<pre class="highlight">
<?=$this->navigation()->menu(); ?>
will result into
<pre class="highlight">
<a href="/page">Page</a>
<a href="/page">Create new page</a>
Solution: Modify the assemble() method.
In Zend_Rest_Route, line 248, add:
<pre class="highlight">
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:
<pre class="highlight">
if (!empty($url) || $controller !== $this->_defaults[$this->_controllerKey]) {
$url = '/' . $controller . $url;
}
with
<pre class="highlight">
$url = '/' . $controller . $action . $url;
Posted by Alex Zinchenko (admloki) on 2009-09-02T06:26:58.000+0000
Much elegant solution.
Posted by Alex Zinchenko (admloki) on 2009-09-02T06:28:07.000+0000
Now it's really elegant solution.
Posted by Matthew Weier O'Phinney (matthew) on 2009-09-02T06:29:18.000+0000
You need to specify the route with your pages:
<pre class="highlight">
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.
Posted by Alex Zinchenko (admloki) on 2009-09-02T07:34:37.000+0000
My application uses Zend_Rest_Route as default router. I don't think its because of undefined route name in Zend_Navigation_Page initialization.
Posted by Alex Zinchenko (admloki) on 2009-09-02T07:38:51.000+0000
Matthew, i checked that - solution you provided not working.
Posted by Alex Zinchenko (admloki) on 2009-09-02T13:25:32.000+0000
Found a solution for issue ZF-7760. Please check.
Posted by Robin Skoglund (robinsk) on 2009-09-19T15:57:52.000+0000
Posted by Luke Crouch (lcrouch) on 2009-09-29T13:36:41.000+0000
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.
Posted by Robin Skoglund (robinsk) on 2009-10-16T15:34:06.000+0000
It's been a few weeks now, so I guess this is not an issue anymore.
Alex: Could you provide a reproducable case?
Posted by Dolf Schimmel (Freeaqingme) (freak) on 2009-10-16T16:58:31.000+0000
So, after having a hard time to reproduce the behavior I was totally unable to. The code I used:
<pre class="highlight"><?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.
Posted by Luke Crouch (groovecoder) on 2009-10-17T13:07:27.000+0000
Thanks Dolf.
Posted by Rick Jones (r13ckj) on 2011-01-29T18:59:08.000+0000
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?
Posted by Rick Jones (r13ckj) on 2011-01-29T19:41:59.000+0000
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.