"Override Admin Controller" in magento 1.6

In Manageto, you can override admin blocks and models by just creating a copy of core files into local folder and easily override magento core functionality. But you cannot follow this way to override admin controllers. Let's take a look how to override admin controller in magento.

In our example, we are overriding Mage_Adminhtml_Permissions_UserController. To override admin controller create following files at specified location.

  1. /app/etc/modules/Placement_MyModule.xml
  2. /app/code/local/Placement/MyModule/etc/config.xml
  3. /app/code/local/Placement/MyModule/controllers/Permissions/UserController.php

Step 1 - Create /app/etc/modules/Placement_MyModule.xml

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

Step 2 - Create /app/code/local/Placement/MyModule/etc/config.xml

<?xml version="1.0"?>
<config>
  <modules>
    <Placement_MyModule>
      <version>1.0.0</version>
    </Placement_MyModule>
  </modules>
  <global>
    <rewrite>
      <Placement_MyModule_permissions_user>
        <from><![CDATA[#^/admin/permissions_user/#]]></from>
        <to>/placement_mymodule/permissions_user/</to>
      </Placement_MyModule_permissions_user>
    </rewrite>
  </global>
  <admin>
    <routers>
      <placement_mymodule>
  <use>admin</use>
  <args>
    <module>Placement_MyModule</module>
    <frontName>placement_mymodule</frontName>
  </args>
      </placement_mymodule>
    </routers>
  </admin>
</config>

Step 3 - Create /app/code/local/Placement/MyModule/controllers/Permissions/UserController.php

# Controllers file will not auto included so we have to do it manually
require_once 'Mage/Adminhtml/controllers/Permissions/UserController.php';

class Placement_MyModule_Permissions_UserController extends Mage_Adminhtml_Permissions_UserController
{
  public function saveAction()
  {
     // Your code for Save Action
  }
}

Created At: 22 December, 2024

Views: 12,914



Social Sharing
Search