2

This question already has an answer here:

I want to make some minor changes in AccountController.php. So I have copy AccountController.php from app/code/core/Mage/Customer/controllers/AccountController.php to app/code/local/Mage/Customer/controllers/AccountController.php

But it's not working any idea?

marked as duplicate by Fabian Schmengler, Sander Mangel, 7ochem, liyakat, Anna Völkl Sep 9 '15 at 13:37

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • Make sure cache is properly cleared – Sander Mangel Sep 9 '15 at 12:05
  • change the folder name from customer to Customer/controllers – Marius Sep 9 '15 at 12:07
  • Marius i guess that magento cannot override any controller with NameSpace Mage from local folder..Mean copy from app/code/core/Mage/Customer/controllers to app/code/local/Mage/Customer/controllers... – Amit Bera Sep 9 '15 at 12:18
  • @Arunendra ,You can check magento.stackexchange.com/q/76628/4564 as alternative solution h – Amit Bera Sep 9 '15 at 12:21
  • It's seems that now i have to override it by creating custom module for it. – Arunendra Sep 9 '15 at 12:31
5

Your code will need to look something like...

config.xml

<?xml version="1.0"?>
<config>
    <frontend>
        <routers>
            <customer>
                <args>
                    <modules>
                        <[vendor]_[modulename] before="Mage_Customer">[Vendor]_[ModuleName]</[vendor]_[modulename]>
                    </modules>
                </args>
            </customer>
        </routers>
    </frontend>
</config>

and your class

app/code/local/[Vendor]/[ModuleName]/controllers/AccountController.php

<?php

require_once Mage::getModuleDir('controllers', 'Mage_Customer').DS.'AccountController.php';

class [Vendor]_[Module]_AccountController extends Mage_Customer_AccountController
{
    // do code
}

As a side note, copying block / model classes in to the local code pool is never a good idea. It increases the pain you will experience when you try to upgrade because there might be changes in those files you would have to copy in.

  • 1
    It's work, I was forget that controller can't override by copying from core to local. – Arunendra Sep 9 '15 at 13:23
2

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.

follow this question link

0

Create Custom module look like this below steps:

Step 1:- Create a file Custom_Module.xml at app\etc\module\Custom_Module.xml and add the below code.

<?xml version="1.0"?>
<config>
  <modules>
    <Custom_Module>
      <active>true</active>
      <codePool>local</codePool>
      <version>0.1.0</version>
    </Custom_Module>
  </modules>
</config>

Step 2:- Create a file config.xml at app\code\local\Custom\Module\etc\config.xml and add the below code.

<?xml version="1.0"?>
<config>
  <modules>
    <Custom_Module>
      <version>0.1.0</version>
    </Custom_Module>
  </modules>
  <global>
                <rewrite>        
            <custom_module_customer_accountcontroller>
                <from><![CDATA[#^/customer/account/#]]></from> <!-- Mage_Customer_AccountController  -->
                <to>/module/customer_account/</to> <!-- Custom_Module_Customer_AccountController  -->
            </custom_module_customer_accountcontroller>
                </rewrite>
  </global>
</config>

Step 3:- Create a file AccountController.php at app\code\local\Custom\Module\controllers\Customer\AccountController.php and add the below code.

<?php
require_once "Mage/Customer/controllers/AccountController.php";  
class Custom_Module_Customer_AccountController extends Mage_Customer_AccountController{
        // here your function
}

Hope this helps!

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