Redirect in Front Controller plugin Zend

plugins, redirect, request, response, zend-framework

Solution

If you are looking to redirect if the user is not logged it, the first parameter of dispatchLoopStartup() is a handle to the request object.

public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
    if(!Zend_Auth::getInstance()->hasIdentity())
    {
        $request->setControllerName('auth');
        $request->setActionName('login');
        // Set the module if you need to as well.
    }
}

Problem

I'm trying to centralise my redirects (based on authentication and various other states) into a front controller plugin. So far I've tried: ``` $this->setRequest(new Zend_Controller_Request_Http('my_url')); ``` at various points in the plugin (i.e. from routeStartup to dispatchLoopShutdown) and also: ``` $this->setResponse(new Zend_Controller_Response_Http('my_url')); ``` Can anyone offer some assistance on this, or point me in the direction of a tutorial?

Original source