Magento Redirect from Observer -


i having trouble create working redirect in magento observer.apart need understand why exception in controller not work in observer.

the typical exception done in controller below (adminhtml controller)

$message = $this->__('exception message.'); mage::getsingleton('adminhtml/session')->adderror($message); $this->_redirect('*/*/edit', array('id' => $this->getrequest()->getparam('id'))); return; 

somewhere in blog read below method redirect observer.

mage::getsingleton('core/session')->adderror('exception message.'); mage::app()->getfrontcontroller()->getresponse()->setredirect(mage::geturl('checkout/cart')); mage::app()->getresponse()->sendresponse(); exit; 

i don't understand basic redirection difference when doing observer , controller.

why controller redirection not work when used in observer.

please me out , explain.

thanks lot in advance.

see below link , have posted code might you.

source : http://aaronbonner.io/post/418012530/redirects-in-magento-controllers

redirects in magento controllers in zend framework controllers, output other html want disable viewhelper defaults along of other magic zf typically weaves.

in magento, same thing applies when doing controller redirect.

i noticed on php 5.2 redirect seemed ignored whereas macports 5.3 setup worked. turns out missing trick, , proper redirect in magento done follows:

in mypackage/mymodule/controllers/mycontroller.php :

$this->_redirecturl($this->geturl('http://www.someurl.com/someresource'));   $this->setflag('', self::flag_no_dispatch, true);   return $this; 

without setflag call, redirect ignored. return call stops further code execution , sees redirect actioned.


Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -