Jiew Meng
Jiew Meng

Reputation: 88197

Zend_Controller_Request::setRedirect() does not seem to work?

i am not sure if calling setRedirect from the resource object is the best way. but i wonder why this does not seem to do anything. i have this in a predispatch controller plugin

function preDispatch(Zend_Controller_Request_Abstract $req) {
    ...
    if (!$acl->isAllowed($role, $resource, $privilege)) {  
        ...
        $res = $this->_response;
        $res->setRedirect('/error/?error-handler=unauthorized', 403);
    }
}

if u prefer the whole code, get it @pastebin

Upvotes: 0

Views: 1128

Answers (1)

Benjamin Cremer
Benjamin Cremer

Reputation: 4822

setRedirect() does not stop the dispatchloop from executing. To do the redirect you have to send the headers and exit the process.

$res->setRedirect('/error/?error-handler=unauthorized', 403);
$res->sendHeaders();
exit();

A better way would be to use the Redirector Zend_Controller_Action_HelperBroker::getStaticHelper('Redirector')->gotoUrl()

Upvotes: 4

Related Questions