If you’re looking for solution to customizing Magento admin core functionality or want to change core functionality of any controller. Don’t worry, it’s really very easy. You just need to override controller action with your controller action. In this tutorial, I have explained how to override Magento admin controllers.
Also, read:
- Display Related products on product details page in Magento
- Magento – Models, resource models, and collections
- Know About Magento Object Relational Mapping (ORM)
- Creating Custom Magento URL Rewrites
- Generate CSV file in Magento
How to override magento admin controller action
This example show you override edit action from ProductController.php located app/code/core/Mage/Adminhtml/controllers/Catalog
Step 1: Create new module from app/etc/Justwebdevelopment_Overridecontroller.xml
<?xml version=“1.0”?> <config> <modules> <Justwebdevelopment_Overridecontroller> <active>true</active> <codePool>local</codePool> </Justwebdevelopment_Overridecontroller> </modules> </config>
Step 2: Make config.xml from
app/code/local/Justwebdevelopment/Overridecontroller/etc/config.xml
<?xml version=“1.0”?> <config> <modules> <Justwebdevelopment_Overridecontroller> <version>0.0.1</version> </Justwebdevelopment_Overridecontroller> </modules> <admin> <routers> <adminhtml> <args> <modules> <Justwebdevelopment_Overridecontroller before=“Mage_Adminhtml”>Justwebdevelopment_Overridecontroller</Justwebdevelopment_Overridecontroller> </modules> </args> </adminhtml> </routers> </admin> </config>
Using above code you can override any action from any adminhtml controller. Only you need to make controller file for that.
Here I want to give example of ProductController.php file.
Step 3: Make controller file from
app/code/local/Justwebdevelopment/Overridecontroller/controllers/Catalog/ProductController.php
And first include your default controller class file then write new controller class for update then extends your new controller file to your default controller class like here extends with “Mage_Adminhtml_Catalog_ProductController”. After the define those action which you want to override.
include_once(“Mage/Adminhtml/controllers/Catalog/ProductController.php”); class Justwebdevelopment_Overridecontroller_Catalog_ProductController extends Mage_Adminhtml_Catalog_ProductController { public function editAction(){ echo “Override Product Edit Action…”;exit; } }
If you follow these three steps explained above then when you try to edit any products from backend then it shows this message “Override Product Edit Action…”. Please be careful with module name and controller name.
You may also like:
- Working with php.ini file Configuration
- Control Statements in PHP
- Convert Associative Array into XML in PHP
- Convert XML into Associative Array in PHP
- Using Prepared Statement with PHP & MySQL
- How to Upload File in PHP
- Converting an Array to JSON in PHP
- Converting JSON to Array or Object in PHP
- Manipulating PHP arrays: push, pop, shift, unshift
- Remove Repeated Words From String in PHP
- Converting a PHP Array to a Query String
- 15+ regular expressions for PHP developers
- 10 Most Important Directory Functions in PHP
- 10 little known but useful PHP functions
- PHP Script to Download Large Files Reliably