Magento 1 - Why do controller action predispatch events not fire if the controller is rewritten?

Magento 1 - Why do controller action predispatch events not fire if the controller is rewritten?

July 19, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 1 - Why do controller action predispatch events not fire if the controller is rewritten?

Why Magento 1 Controller Action Predispatch Events Don’t Fire With Rewrite

If you’re working with Magento 1 and find that your controller action predispatch events aren’t firing as expected, especially when the controller is rewritten, you’ve likely stumbled upon a common issue in the platform’s core architecture. Let me shed some light on this problem.

Understanding the Core Controller Class

The core of the issue lies within the Mage_Core_Controller_Varien_Action class, which is the base for all Magento controllers. In its preDispatch() method, you’ll find a critical line:

if ($this->rewrite()) {
    return;
}

This snippet checks if the current controller has been rewritten via an observer or rewrite configuration (app/code/local/Mage/Cms/etc/config.xml or similar). If a rewrite is detected, the preDispatch() method immediately returns without triggering the predispatch event.

The Purpose of the Rewrite Check

The purpose of this check is to optimize performance. When a controller is rewritten, Magento assumes that the rewritten class handles the initial dispatch logic and doesn’t need to fire the default predispatch events. This approach reduces unnecessary event firing and potential conflicts between rewrites and core functionality.

Fixing the Event Firing Issue

Given this understanding, you have a few paths forward:

  1. Rewrite the Rewrite: The cleanest solution is to create your own rewrite of the rewritten class, ensuring that it includes the necessary event triggering. For example:
class Your_Module_Model_Cms_PageController extends Mage_Cms_Model_PageController
{
    public function preDispatch()
    {
        parent::preDispatch();
        // Trigger your custom predispatch event here
        Mage::dispatchEvent('controller_action_predispatch_your_custom_event');
    }
}

Remember to register this rewrite in app/code/local/Your_Module/etc/config.xml.

  1. Event Observer Rewrite: If you’re unable or unwilling to create a full class rewrite, you can create an observer that rewrites the default predispatch event.
class Your_Module_Model_Obs_Cms_PageControllerPredispatch
{
    public function execute($observer)
    {
        // Custom logic before Magento's core handling
        Mage::dispatchEvent('controller_action_predispatch_your_custom_event');
        return $this;
    }
}

Again, ensure you register this observer in the config.xml file.

  1. Core Modification: As a last resort, you could modify the core Mage_Core_Controller_Varien_Action class to always fire the event before returning if rewritten. However, I strongly recommend against this approach due to upgrade issues and potential conflicts with other rewrites or core updates.

Conclusion

The rewrite check in Magento 1’s controller action is a performance optimization intended to reduce unnecessary event firing. To get your predispatch events to trigger when controllers are rewritten, you’ll need to create your own rewrites or observers that handle the necessary event triggering before the core logic executes.

Remember, proper module registration and configuration.xml updates are crucial for successful rewrites.

For more insights on Magento 1 development best practices and solutions to common challenges like this one, check out our comprehensive guides at Laravel Company.

Happy coding!

Magento 1 Cache Performance Security

Our network