How to override a controller in Magento

How to override a controller in Magento

In several time ,we need to override a controlller.How to override a controller in Magento.
There are two process available:
1.Basic Old process.
2.Upgrade Process from Magento CE 1.5.0.

First have describe second process. It available from Magento CE 1.5.0.Where, i have

Overriding controllers magento core controller

.I have using before tag for use to

override controller of a module-


Here ,step to override a controllers:
a)First check which module ,i want to override.

Ex1: Suppose have override magento Magento Core Module Mage_Contacts and want override IndexController.php
Write below code

Here <contacts> is frontend routers for Mage_Contacts,
and In <customcontacts before=”Mage_Contacts”>Amit_Customcontacts</customcontacts> , <customcontacts is a unique name this rewrite.
Amit_Customcontacts ,Amit is My module namespace ,and Customcontacts is Module name.
Location:app/code/local/Amit/Customcontacts/etc/config.xml and full code for this file

b)Now need to define Controller file, Which name should be same name Overriding Controller. If override Customer Module AccountController.php then it overridden Controller name should be AccountController.php. Also need to include parent class file and the class.
Ex: As per as, override IndexController.php then overridden file is IndexController.php

As contacts us routers is contacts/index/index that means IndexController.php and index Action and IndexController.php path is Mage/Contacts/controllers then Override controller(IndexController.php) path is
app/code/local/Amit/Customcontacts/controllers /

c)Add the following to use the same update handle as before:
I have layout file that the file to change is app/design/frontend/[myinterface]/[mytheme]/layout/mymodule.xml

Add the following lines:

Second Procedure:

Another process is basic magento process. Where overload is contacts controllers
Where customcontacts routers to contacts

b)rewrite rule could be added to the database instead

Where customcontactsunique is rewrite identifier code which should be unique.

Here picture of Basic procedure

How to override a controller in Magento

Rest of Indexcontrollers.php file code is same as above.

Most Import:Also,need to module file Amit_Customcontacts.xmlwhich is located at app/etc/modules .it importance both Process


















Leave a Reply

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