Skip to content

Magento: Example Rewrite Multiple Controller Class

i just figure it out how to do this …let me show you 😀

let say we want to rewrite customer account controller class by module 1 & module 2, here the code

 

Module 1

Controller 1

require_once(“Mage/Customer/controllers/AccountController.php”);

class KS_Module1_Customer_AccountController extends Mage_Customer_AccountController
{

public function loginAction()
{

/* first rewrite here */
}
}

 

Config Module 1

           <customer>
<args>
<modules>
<KS_Module1 before=”Mage_Customer”>KS_Module1_Customer</KS_Module1>
</modules>
</args>
</customer>

 

Module 2

Controller Module 2

require_once “KS/Module1/controllers/Customer/AccountController.php”;
class KS_Module2_Customer_AccountController extends KS_Module1_Customer_AccountController{

public function loginAction()
{
}
}

Config Module 2

<frontend>
<routers>

<customer>
<args>
<modules>
<KS_Module2 before=”KS_Module1″>KS_Module2_Customer</KS_Module2>
</modules>
</args>
</customer>

</routers>
</frontend>

<ks_module2_customer_accountcontroller>
<from><![CDATA[#^/module1/customer_account/#]]></from>
<to>/module2/customer_account/</to>
</ks_module2_customer_accountcontroller>

Global Configuration Module 2

<?xml version=”1.0″?>
<config>
<modules>
<KS_Module2>
<active>true</active>
<codePool>local</codePool>
<version>1.0.0</version>
<depends>
<KS_Module1 />
</depends>
</KS_module2>
</modules>
</config>

Share

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.