Override magento controller
Modifying magento core file is not at all good idea. All core files that we have modified will be smashed while magento upgrade.
Magento have a feature to keep our custom code in local(app/code/local) folder. Inside that folder we can keep our custom codes safely.
There are 2 way to override magento core module.
Follow the steps correctly, its case-sensitive so keep your eye closely.
step:2config.xml - Configuration for our module
Step:3AccountController.php
After completing, don't forget to clear Magento cache. Make sure that your module is in active [admin->system->configuration->Advanced->Advanced]
Is this post useful? Please comment on this!
Magento have a feature to keep our custom code in local(app/code/local) folder. Inside that folder we can keep our custom codes safely.
There are 2 way to override magento core module.
- Create same folder structure in local folder as like in core.
Ex: If we want to override the Account controller in app/code/core/Mage/Customer/controllers/AccountController.php we can do by just creating same folder structure in local folder like app/code/local/Mage/Customer/controllers/AccountController.php. Here Account Controller have overridden by the file in local directory. - Another way is to override controller using our own module.
At first, i was frustrated because i was followed 4 more tutorials but couldn't able to override core controller. Finally got the solution from webspeaks.com that how to override controllers in magento
Follow the steps correctly, its case-sensitive so keep your eye closely.
Creating your own module
- Create Ws_Customer.xml file inside app/etc/modules/
- Create Ws(namespace) folder inside app/code/local/
- Create Customer(module) folder inside app/code/local/Ws
- Create config.xml file inside app/code/local/Ws/Customer/etc/
- Create AccountController.php file inside app/code/local/Ws/Customer/controllers/
<?xml version="1.0"?>
<config>
<modules>
<Ws_Customer>
<active>true</active>
<codePool>local</codePool>
</Ws_Customer>
</modules>
</config>
step:2config.xml - Configuration for our module
<?xml version="1.0"?>
<config>
<modules>
<Ws_Customer>
<version>0.0.1</version>
</Ws_Customer>
</modules>
<frontend>
<routers>
<customer><!-- Name of core module to be overridden-->
<args>
<modules>
<Ws_Customer before="Mage_Customer">Ws_Customer</Ws_Customer><!-- Tell Magento to call our custom module before the Mage/Checkout module -->
</modules>
</args>
</customer>
</routers>
</frontend>
</config>
Step:3AccountController.php
require_once("Mage/Customer/controllers/AccountController.php");
class Ws_Customer_AccountController extends Mage_CUstomer_AccountController{
//Add your stuffs here
public function indexAction(){
echo 'Index action have been overriden!!';
parent::indexAction();
}
}
After completing, don't forget to clear Magento cache. Make sure that your module is in active [admin->system->configuration->Advanced->Advanced]
Is this post useful? Please comment on this!
We have followed the override the controller in the app/code/local/Mage/Customer/controllers/AccountController.php ,but still its not working .
ReplyDelete