4

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.

8

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

  • If so, I have to create a module to extend a function in IndexController, isn't it? Is there really no way to autoloaded controllers with local code pool? – Toan Nguyen Jan 29 '15 at 3:41
  • Like I said, it will not work for controllers. Besides copying files to local code pool is bad practice. All class rewrites should be done via modules. – Lord Skeletor Jan 29 '15 at 3:43
2

I would like to add that though it is possible to copy a model or block to local to get this working that you should not do this as it will be an issue when you decide to update Magento.

You have a few options here:

  1. Rewrite the model using the rewrite node in your extension's xml,
  2. Leave the model and find an event that works for your needs,

I would always try to choose the second option but since I do not know your needs I will go with number 1 for this answer.

To rewrite the model simply add the follow to your module's config.xml

<global>
    <models>
        <your_module>
            <class>Your_Module_Model</class>
        </your_module>
        <admin>
            <rewrite>
                <session>Your_Module_Model_Admin_Session</session>
            </rewrite>
        </admin>
    <models>
</global>

Now what you can simply do is create the model Your_Module_Model_Admin_Session that extends the model Mage_Admin_Model_Session and you can make your changes in there.

Final note I would consider investigating if there are any events that will fit your needs.

  • I don't know that, that's very useful information, thank you David. Actually, I modified login() function, inside if ($redirecUrl) { I removed $this->_response..., then return true; – Toan Nguyen Jan 30 '15 at 2:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.