How can I point admin action method to other than `indexAction()`?
-
12-12-2019 - |
Question
In my module, I am setting up my menu like this.
<menu>
<catalog>
<children>
<rkt_arattr translate="title" module="rkt_arattr">
<title>Manage My Custom Attribute</title>
<sort_order>100</sort_order>
<children>
<install_attr translate="title" module="rkt_arattr">
<title>Install My Attribute</title>
<action>adminhtml/catalog_arattr_install</action>
<sort_order>10</sort_order>
</install_attr>
</children>
</rkt_arattr>
</children>
</catalog>
</menu>
The code that you need to concentrate is action
<action>adminhtml/catalog_arattr_install</action>
For this value, my url looks like this
www.mydomain.com/admin/catalog_arattr_install/index/key/[key_value]
As per this ulr, Magento expects a controller setup like this.
File : app/code/local/Namespace/Modulename/controllers/Adminhtml/Catalog/Araattr/InstallController.php
<?php
class Namespace_Modulename_Adminhtml_Catalog_Arattr_InstallController extends Mage_Adminhtml_Contorller_Action
{
public function indexAction()
{
}
}
However this is not what I want.. I need my url parse like this.
www.mydomain.com/admin/catalog_arattr/install/key/[key_value]
Means I want the below method get called when click on the menu
File : app/code/local/Namespace/Modulename/controllers/Adminhtml/Catalog/ArattrController.php
<?php
class Namespace_Modulename_Adminhtml_Catalog_ArattrController extends Mage_Adminhtml_Contorller_Action
{
public function installAction()
{
}
}
But it seems that, magento always looks for indexAction()
when we setup a menu.
Is there any way to direct to my custom action when click on the menu ?
Solution
Should be as simple as adding extra parts to the action
node.
<action>adminhtml/your_controller/your_action</action>
Check out how the downloads part of the admin section works.
<action>adminhtml/report_product/downloads</action>
Here the controller is Mage_Adminhtml_Report_ProductController
and the action is downloadsAction
OTHER TIPS
Your action
path should be adminhtml/catalog_arattr/install
to define the install
section of the path as the action. Each /
slash separates the module, the controller and then the action so as you only have 1 slash the action is assumed to be indexAction()
. With the above URL the request will target the Namespace_Modulename_Adminhtml_Catalog_ArattrController
and inside that installAction()
. You will of course need to change the location of the controller to one directory higher up.