Preempting the dispathcer


I have an afterExecuteRoute route set up in my base Controller class. To redirect, I use:


I track XDebug and notice afterExecuteRoute still executes after the redirect code. How do I prevent this method from firing when I redirect?

edited Nov '15

This works:

$this->response->redirect('', true);

Is there a better way?

UPDATE: XDebug still shows afterExecute firing. Now using a $stopDispatcher instance variable. :(

edited Nov '15

afterExecuteRoute cannot stop the dispatch loop, you should use beforeExecuteRoute.

Redirect will generate a full response with 30x (302 if i remember correctly) code, so view->disable is not really needed.

You may also consider using dispatcher->forward to render the login page in the same request, thus saving an extra redirect. The URL will stay the same though.