Home > Zend Framework > Using Redirection Outside Of A Controller In Zend Framework

Using Redirection Outside Of A Controller In Zend Framework

February 2nd, 2009 Leave a comment Go to comments

I had a situation the other day where I had an application in Zend Framework and I wanted to redirect a user to another page. This is fine if you are inside a controller as you can use the _redirect() controller function, but in this instance I was in a plugin that didn’t have direct access to the controller.

The solution is to use the getResponse() method, which is accessible to plugins, and which will retrieve the response object. The response object has a function called setRedirect() that is used to redirect. Any headers that have been issued will be overwritten by this function. The following code can be run inside your zend framework plugins to redirect the user to a different page.

$this->getResponse()->setRedirect('http://another/page/', 301);

The setRedirect() function takes two parameters. The first is the URL to be redirected to and the second is the HTTP response code.

Information, services, and products:
Pressure washer and leaf blowers online
  1. No comments yet.
  1. No trackbacks yet.