Wednesday, October 28, 2015

Be careful when overriding Magento Controller constructors

I've found this bug recently in one of my Magento extensions:

Fatal error: Call to a member function getActionName() on a non-object in /my_path/htdocs/app/code/core/Mage/Core/Controller/Varien/Action.php on line 200

The error was generated while I was tryting to run an action from my custom controller. My custom controller exteneded the Mage_Adminhtml_Controller_Action controller.

It was working fine until I have added a default constructor to my controller:

function __construct()

        $this->mHelper =  Mage::helper("myextension/data");

After this, I was getting the error I mentioned earlier. After checking the definition of class defined in  Core/Controller/Varien/Action.php, I have realized that it's parametrized constructor was never being called, and that caused my error later on at runtime.

I have removed my default constructor, and things went back to normal.
Hope this tip helps someone.

No comments:

Post a Comment

Ubuntu 12.04, 14.04, 16.04 - auto start an app or script before login

To run a command or application at startup, even before the user has logged in, you can use this file: /etc/rc.local The commands entered...