(on Thursday, 05 February 2009, 05:42 PM +0100):
> > In case of certain conditins i need to redirect 301 to other URL.
> >
> > I am wondering which option should be better for this:
> > a) i am missing something so that's why redirect doesn't work; i would
> > try with a header('Redirect...') but i would like to stay with ZF
> > rather...
> > b) i should better use my custom router class instead, and redirect
> > would be possible here (and not into route itself)
> > c) i should do the checking before URL goes to router (maybe on
> > bootstrap)
> > d) other option i may miss now
>
> I had the same problem. I have created a redirect controller action that
> use the redirector action helper to do redirection. This means that in
> the router I forward the request to my redirect controller action and it
> will redirect the client to the right url.
>
> I don't like this solution very much. I would prefer option (a) but it
> seems not work.
The router is the wrong place to do this. Routing is simply decomposing
the request environment into artifacts.
I'd do this within a front controller plugin that operates during
routeShutdown() instead:
class My_Plugin_RedirectEarly extends Zend_Controller_Plugin_Abstract
{
public function routeShutdown(Zend_Controller_Request_Abstract $request)
{
if ( /* certain criteria met in request object */) {
$response = $this->getResponse();
$response->setRedirect(/*...*/);
$response->sendResponse();
exit;
}
}
}
You don't necessarily need to do the sendResponse()/exit there, but it
gets the point across.
--
Matthew Weier O'Phinney
Software Architect | matthew@zend.com
Zend Framework | http://framework.zend.com/
没有评论:
发表评论