0

I've got 2 links in my layout.phtml and a route in the bootstrap:

1. Link:
echo $this->url(array('controller' => 'aktuelles', 'action' => 'index'), null, true );
// creates: http://localhost/aktuelles

2: Link
echo $this->url(array('controller' => 'projekte', 'action' => 'wohnen', 'projektId' => 26), 'projekte-galeria', false);
// creates: http://localhost/projekte/wohnen/26

Route:
$front = Zend_Controller_Front::getInstance();
$router = $front->getRouter();
$route = new Zend_Controller_Router_Route(  'projekte/wohnen/:projektId', 
                                            array(  
                                                    'module' => 'web',
                                                    'controller' => 'projekte',
                                                    'action' => 'wohnen',
                                                    'projektId' => null)
                                            );                  
$router->addRoute(  'projekte-galeria', $route); 

When I load the page everything is displayed correctly and the urls are all correct.

Problem: As soon as i click on the second link (http://localhost/projekte/wohnen/26), the first link is changing:

from: localhost/aktuelles

to : localhost/projekte/wohnen

Why is the link changed?

PeeHaa
  • 71,436
  • 58
  • 190
  • 262
Flexer
  • 131
  • 2
  • 7

2 Answers2

2

Try to force to use the default route: instead of null use 'default' as the second parameter in the first url.

BTW - the part 'controller' => 'projekte', 'action' => 'wohnen' in the second url is redundant, because you predefine these parameters in the route. The second link could by simplified like this:

echo $this->url(array('projektId' => 26), 'projekte-galeria', false);
Ondrej Machulda
  • 998
  • 1
  • 12
  • 24
  • Thanks, this works. But why do i have to set it with the 'default' parameter instead of null? I thought null defines the default route? – Flexer Jan 26 '12 at 02:20
  • Well, see the apidoc for the Url View Helper: _The name of a Route to use. If null it will use the current Route_. So it doesn't set it to `default`, it instead says "use the route used for routing this action". – Ondrej Machulda Jan 28 '12 at 13:55
0

Have a look at this solution as an alternative way to handle routes Simple rewrites in Zend Framework

Community
  • 1
  • 1
dkcwd
  • 569
  • 3
  • 9