php - Magento copy controller to local
When I copy some
core/Mage/Adminhtml/Block/ files to
local/Mage/Adminhtml/Block/ everything work's fine, but if I copy controller to
local/Mage/Adminhtml/controllers - core controller still works and system don't see my local/ ... controller.
It's because controllers are loaded in a different way than other type classes. You don't do it by referencing to
Mageclass. To know how they are loaded lets look at a standard Magento router and its method
Then lets look at
Mage_Core_Model_Config::getModuleDir()method (config class is referenced inside
As you can see, Magento get real module code pool in this case. That's why simple copy won't work. You have to rewrite controllers.
If you don't know how to properly rewrite a controller let me know in the comments. I will update this answer accordingly.
To rewrite a controller you need to create a new module in local code pool (or use existing one). If you don't know how to create a module check this SO topic. Lets assume that you want to make a rewrite of Magento Onepage checkout controller.
In config.xml of a module add this:
Next, create a controller in your module in app/code/local/MyNamespace/MyModule/controllers. Name it the same as controller that is being rewritten. You must use the same folder structure as Magento use. In our case we create a
OnepageController.phpin controllers folder.
And that's it! Note that you need to flush Magento cache after doing this. Admin controllers are very similar to rewrite. Just change a
<admin>and you're good to go. Usually it's a good practice to place admin controllers to
controllersfolder. So example config.xml would look like this:
Note that controller path has changed to
MyNamespace_MyModule_Adminhtmlbut it does not contain
Magento will automatically look to controllers with the same relative path and controller name.