Redirect with Zend Framework

submit to reddit

Once I wrote about redirecting with Zend Framework, but what I missed back than was a common mistake. Although the code from my post is working, to be completely correct after redirecting I’d to add an exit() statement.

This is important because the header is changed and if something goes after the redirect there will be some problems. Finally the correct snippet is:

public function() {
	$this->_redirect('some_url');
	exit();	
}

Related posts:

  1. Redirecting with Zend Framework
  2. Download Files with Zend Framework
  3. Redirecting with Zend Framework – part 2

You are a GREAT developer? Click here to answer the weekly quiz!

This entry was posted in micro tutorial, PHP, zend framework and tagged , , , , , , , . Bookmark the permalink.

One Response to Redirect with Zend Framework

  1. Andrew says:

    You can use options instead:

    $this->_redirect($this->view->url(array(), null, true), array(‘exit’ => true));

    to redirect on main. Take notice about:

    array(‘exit’ => true)

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="">