views:

44

answers:

1

i seen from here 2 ways to redirect from a controller plugin ... i wonder which is more efficient. i am wondering in the 2nd method, it maybe slower because the response is created? what happens in the 1st method tho? it will redirect immediately?

$request->setModuleName('default')
        ->setControllerName('search')
        ->setActionName('form')
        ->setDispatched(false);

or

$this->_response->setRedirect('redirecturl'); 
A: 

The first method is an application redirect: You define that the requestsd operation is within anorher controller, so the same http request is used to execute the action

The second method is an http redirect: The http-response will have an http-location-redirect, so the client will fire a second a http-request to get the result

The first is definetly the most efficient.

PS.: You can call the forward-method of the controller to dispatch another action

Tobias P.
What if you wanted to also change the displayed URL?
Alister Bulman
@Tobias P.: i am in an controller plugin is forward available? with the request object, can i add a response code eg. HTTP 401 for login required? @Alister Bulman: if i think `_redirect('/page1')`?
jiewmeng