Hmm. $response->setRedirect() assumes you are providing it a url so its
probably best if that were an absolute path.
Also, it does not stop the dispatchloop from executing, so you might
have to do $request->setDispatched(true);
To get a sense of how redirecting is handled, you might want to have a
look at the Redirector action helper:
http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Controller/Action/Helper/Redirector.php
specifically, have a look at gotoUrl() as well as redirectAndExit()
-ralph
Gregorio wrote:
Hello, everybody:
I've got a controller helper plugin that has a preDispatch method in it.
It's checking to see if the user has logged in via an off-site
authentication service, and if not, redirects the user to an Authentication
controller do that part of the work.
However, the redirect isn't working. I took a look at the header stack and
it wasn't there. However, if I add a dummy header, it works. Here's some
code to help explain:
class Plugin_CasAuth extends Zend_Controller_Plugin_Abstract
{
public function preDispatch(Zend_Controller_Request_Abstract $request)
{
$request = $this->getRequest();
$response = $this->getResponse();
$session = new Zend_Session_Namespace('Zend_Auth');
// No need for any more processing if this is the Authenticate
controller.
if ('authenticate' === $request->getControllerName()) {
return true;
}
if (empty($session->storage))
{
$response->setRedirect('authenticate');
// If I comment the following line, there's no redirect. User
gets sent
// directly to the main index controller.
$response->setHeader("Test", "This is a test!");
}
}
}
The problem is in the last if block.
Any ideas?
Thanks!
Greg