Redirecting with Zend Framework

Many of the web applications need to be redirected to some given URI sooner or later. In that scenario like redirecting to the profile page after login, which is very common to almost every app, you need to change the URI of the browser after the login form is validated. You can make this by simply using the built in header function in PHP. In other terms the most popular method to redirect in Zend Framework, don’t know why, but this is the _forward method of the controller actions:

$this->_forward('action-name');

The problem here is that thus you get to the given action name, or controller/action but the URI of the browser stays as it is from the caller action.

If you’d like to redirect, like the header function will do it you should use the following construction:

$this->_helper->redirector->gotoRoute(array(
   'controller'=> 'contrlname',
   'action' =>'actionname'));

Related posts:

  1. Redirecting with Zend Framework – part 2
  2. Zend Framework – Disable Zend Layout
  3. Zend Examples: GET Parameters Default Value
This entry was posted in PHP, web development, zend framework and tagged , , , , . Bookmark the permalink.

One Response to Redirecting with Zend Framework

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">