Jiew Meng
Jiew Meng

Reputation: 88207

Zend Framework: Redirect from Controller Plugin which is more efficient

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'); 

Upvotes: 3

Views: 2551

Answers (1)

Tobias P.
Tobias P.

Reputation: 4664

The first method is an application redirect: You define that the requested operation is within another 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.

Upvotes: 5

Related Questions