开发者

How to override a redirect set previously in request processing

This has bothered me for a while and I've avoided it but the time has come! Often when extending core Magento functionality, whether using the Event-Observer pattern or by overriding a controller (only if absolutely necessary!), the core code will have already set a redirect using $this->getResponse()->setRedirect($url); or similar.

If I want to override that behaviour and have the response rendered in the current request/response cycle, how can I unset or nullify the redirect?

Looking through the type hierarchy to Zend_Controller_Response_Abstract which is the grandparent of Mage_Core_Controller_Response_Http, there are methods to clearHeaders() which would wipe out the Location header that is controlled by setRedirect() but obviously it will wipe out any other headers as well.

Worse case would be to getHeaders(), clearHeaders() and then iterate through all the other Headers with setHeader(), but that seems painful. Any suggestions wel开发者_运维技巧come.

===============

EDIT

As pointed out by @xzyfer, the clearHeader() method does exist in some of the Magento editions. For clients still working on older codebases, how would you recommend implementing this. I'm hesitant to override Mage_Core_Controller_Response_Http as it's such a key class...

Thanks,

Jonathan


Zend_Controller_Response_Abstract has a clearHeader method

$this->getResponse()->clearHeader('Location');

You'll also have to override the response code:

$this->getResponse()->setHttpResponseCode(200);

Just a guess from a quick look at the source of Zend_Controller_Response_Abstract assuming no other magic is going on in one of the child classes this should do the job.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜