Again, what are you trying to do? Redirecting someone from sysconfig to your controller is odd UX at best, even if you redirect back to sysconfig after your code executes. If that's all you're doing, you should be consuming the POST and letting sysconfig behave as normal.
The reason your (first) redirect isn't working is that after this event fires, execution flows back to the controller action, which then sets its own redirect per usual:
class Mage_Adminhtml_System_ConfigController extends Mage_Adminhtml_Controller_Action
{
public function saveAction()
{
// snip ...
try {
// snip ...
Mage::dispatchEvent("admin_system_config_changed_section_{$section}",
array('website' => $website, 'store' => $store)
);
// snip ... }
catch (Mage_Core_Exception $e) {
// snip ...
}
catch (Exception $e) {
// snip ...
}
// snip ...
$this->_redirect('*/*/edit', array('_current' => array('section', 'website', 'store')));
}
You can get around this in a couple ways:
- (not ideal) Flush the response after setting the redirect in your browser; while this obeys your current intent, know that you are preventing subsequent native code from executing both in the action and in
postDispatch()
.
- (better, but still pretty ugly) Instantiate your observer as a singleton, set a flag, and then set that observer class to also consume the
controller_action_postdispatch_adminhtml_system_config_save
event using a different method which will set your redirect.
E.g.
public function checkShouldRedirect()
{
$response = Mage::app()->getResponse();
//use 'mysection' to check we are in correct section
if (self::$flag==true && $this->getRequest()->getParam('section') == 'mysection') {
$response->setRedirect(
Mage::helper('adminhtml')->getUrl('myrouter/adminhtml_test/validate')
);
//below is only necessary for option 1
//$response->sendResponse();
}
}
If you are going to engage in the second option - and provided that you aren't opposed to the action saving the open panel state - you might as well just set your observer to consume only the postdispatch event, since you can test that you are saving your section by testing the section
param.
You cannot override that controller.
Well...actually you can but it will have no effect.
The Mage_Adminhtml_Controller_Action
class is never instantiated. It is there as a common parent class for the rest of the admin controllers.
even if you find a way to rewrite it all the other admin controllers will extend the original class so your modification will be useless.
If you want to change something in it you have to copy it to app/code/local/Mage/Adminhtml/Controller/Action.php
and make your modifications there.
Here are more details about why you cannot rewrite some classes in Magento
Best Answer
The from/to rewrite is, in my opinion, there to make your extensions SEO friendly.
For example a 'brands' extension would rewrite from the default
domain.com/brandsextension/index/list
to a nicedomain.com/brands/
. Using it to reroute Magento core extensions to your own controller works fine but if it ever changes URL's from for examplecheckout/cart/
tocheckout/shoppingcart
it would break your extensions functionality.I would suggest going with the second option since it is, as far as I know, more robust. But this is all opinion based so feel free to correct me ;)