Magento Core File Override – Copy Core File to app/code/local/Mage Can’t Overload

ce-1.9.1.0controllersoverrides

I have 2 files need to be overload

core/Mage/Admin/Model/Session.php

and

core/Mage/Adminhtml/controllers/IndexController.php

I already copy it to local with same structure, but the bad news is it wasn't overloaded. I can overload Block in local folder before. Now, I want to know why and how to do it.

Best Answer

Copying files to local code pool will only work for blocks, helpers and models. You cannot override controllers using this method since they are not autoloaded like other classes.

So the only way to do it is via custom module. You will need following definition in your config.xml

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <Foo_Bar before="Mage_Adminhtml">Foo_Bar_Adminhtml</Foo_Bar>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

And in your controller class you need to add this:

require_once Mage::getModuleDir('controllers', 'Mage_Adminhtml') . DS . 'IndexController.php';
class Foo_Bar_Adminhtml_IndexController extends Mage_Adminhtml_IndexController
{

Your controller class should be in local/Foo/Bar/controllers/Adminhtml/IndexController.php