1

Is it possible to use the Routes ID to redirect to within the controller?

For example, I predefine the login and logout URL with the id of login and logout. In my controller I determine the user needs to be logged out, can I redirect them to that route using the routes id?

Bootstrap

$router->addRoute('logout',new Zend_Controller_Router_Route('logout', array('module' => 'user', 'controller' => 'index', 'action' => 'logout'))); $router->addRoute('login', new Zend_Controller_Router_Route('login', array('module' => 'user', 'controller' => 'index', 'action' => 'login'))); 

Controller

return $this->_redirect('login'); 

Currently the above wouldn't work, Id have to use /login (aka the base URL to the route).

4
  • 1
    Why you use return, without return "$this->_redirect('login')" affairs? Commented Aug 31, 2012 at 15:26
  • +1 for sensible comment! :LOL: Commented Aug 31, 2012 at 17:07
  • @azz0r when you say route-id, What is route-id? Commented Aug 31, 2012 at 17:08
  • Btw.. +1 for a good question! Am researching...... Commented Aug 31, 2012 at 17:11

2 Answers 2

1

I had a similar requirement recently too, the way I solved it was to use the router to assemble the url, and then perform the redirect.

$redirectUrl = Zend_Controller_Front::getInstance()->getRouter()->assemble($userParams, $routeName); $this->_redirect($redirectUrl); 

See Zend_Controller_Router_Interface::assemble

Sign up to request clarification or add additional context in comments.

Comments

0

From Zend Framework 1.8

$route = new Zend_Controller_Router_Route( 'index/:ident', array( 'module' => 'user' 'controller' => 'index', 'action' => 'login' ), array( // match only digits 'ident' => '\d+' ) ); 

1 Comment

I know how to to define a route (see my first part). Im not sure you understand my question

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.