Saturday, October 19, 2013

How To Redirect From the Bootstrap in Zend Framework 1x

If you need to redirect from the Bootrstrap context, you can do:

$front = Zend_Controller_Front::getInstance();
$response = new Zend_Controller_Response_Http();
$response->setRedirect(Zend_Registry::get('config')->et->core->url . '/' . $args[1]);

The most simplistic, basic PHP approach would be:

 header("Location: " . Zend_Registry::get('config')->et->core->url . '/' . $args[1]);

Note: The ob_* functions are to terminate the output buffering routine of Zend Framework and start sending headers to the browser.


 header("Location: " . Zend_Registry::get('config')->et->core->url . '/' . $args[1]);

Note:  the "exit" will force Zend Framework to reach the EOF (end of file) and thus start sending the headers to the browser.

Whichever method you choose would work. Re: their advantages, convention-wise the first one is the most ideal, the fastest however would be the last.

  • Related Links Widget for Blogspot

No comments: