Magento: Controller URL construction and redirection
Constructing the controller url. In a controller or block, you can just use $this->getUrl($url)
Mage::getUrl('module/controller/action');//Example url pattern Mage::getUrl('helloworld/index/index');//hellow world index page Mage::getUrl('checkout/cart');//checkout cart index page
Redirecting to an url by getting the global response object. This works anywhere in Magento as long as there is response object.
Mage::app()->getResponse()->setRedirct(Mage::getUrl('module/controller/action')); Mage::app()->getResponse()->setRedirct(Mage::getUrl('helloworld/index/index')); Mage::app()->getResponse()->setRedirct(Mage::getUrl('checkout/cart'));
Redirecting to an url in an observer function by getting a response object from the observer.
$observer->getResponse()->setRedirect(Mage::getUrl('module/controller/action')); $observer->getResponse()->setRedirect(Mage::getUrl('helloworld/index/index')); $observer->getResponse()->setRedirect(Mage::getUrl('checkout/cart'));
Redirecting to an url in a controller function.
$this->getResponse()->setRedirect($this->getUrl('checkout/cart')); $this->_redirect('checkout/cart');
Search within Codexpedia
Custom Search
Search the entire web
Custom Search
Related Posts