Magento Module with Frontend and Admin Features

I am currently working on a custom module for Magento. I understand the basics of packages, modules, and routers, and I created the front of my module.

However, now I turn to the administrative side of things. However, I'm a little confused about how to add the administrative part to my routers and make it call the appropriate controller.

Suppose I created these routers ...

<frontend> <routers> <slider> <use>standard</use> <args> <module>Mypackage_Myodule</module> <frontName>Mymodule</frontName> </args> </slider> </routers> </frontend> <admin> <routers> <mymoduleadmin> <use>admin</use> <args> <module>Mypackage_Myodule</module> <frontName>Mymodule</frontName> </args> </mymoduleadmin> </routers> </admin> 

I assume that both of these routers will try to call the /IndexController.php controllers and therefore the same functions? Is it possible to configure things so that my routers call different controllers depending on whether they are an interface or an administrator? Is this possible, or do I need to configure an interface module and an administrator module?

I apologize if this is a question of a school boy, but it bothers me a bit, and in fact I just want to find out the most effective way to create a custom module with interface and administrator functions.

+4
source share
2 answers

Depending on the area (frontend or adminhtml), a frontend or adminhtml router is sent.

Therefore, you don’t have to worry about being confused as long as you use different controller files for frontend and adminhtml, the frontend controller extending from Mage_Core_Controller_Front_Action and adminhtml extending from Mage_Adminhtml_Controller_Action .

Frontend / Adminhtml routers can be defined as (just syntax):

 <frontend> <routers> <[module]> <use>standard</use> <args> <module>[Namespace]_[Module]</module> <frontName>[module]</frontName> </args> </[module]> </routers> </frontend> <admin> <routers> <[module]> <use>admin</use> <args> <module>[Namespace]_[Module]</module> <frontName>[module]</frontName> </args> </[module]> </routers> </admin> 

And you can create interface controllers under: app/code/[codePool]/[Namespace]/[Module]/controllers/
For instance:

 <?php //file: app/code/local/MagePsycho/Testmodule/controllers/IndexController.php class MagePsycho_Testmodule_IndexController extends Mage_Core_Controller_Front_Action { public function indexAction(){ } } 

To access it from the URL: http://your-magento-url/testmodule/index/index
and adminhtml controllers: app/code/[codePool]/[Namespace]/[Module]/controllers/Adminhtml/
For instance:

 <?php //file: app/code/local/MagePsycho/Testmodule/controllers/Adminhtml/IndexController.php class MagePsycho_Testmodule_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action { public function indexAction(){ } } 


To access it from the URL: http://your-magento-url/testmodule/adminhtml_index/index
(You can see the Adminhtml folder to separate adminhtml controllers)

Hope this gave you some info.
Thanks

+2
source

Look at my similar question: Admin route in user modules

I would also recommend using

 <admin> <routers>   <adminhtml>     <args>       <modules>         <modulename before="Mage_Adminhtml">Namespace_Module_Adminhtml</modulename>       </modules>     </args>   </adminhtml> </routers> </admin> 

This will allow you to avoid using the adminhtml part in routes, so your module URL will have a simple and clean URL, for example, kernel modules, for example. admin/mymodule

+1
source

All Articles