Welcome back to Magento Tutorial series!
In lesson 5, we have learned how to create and upgrade a Magento module.
Today we move forward to lesson 6.1: Create a Magento module in backend: Add a Magento menu in backend.
In this lesson, we would learn how to:
- Configure the adminhtml router
- Add Magento menu from file adminhtml.xml and configure ACL for menus
- Add controllers for each Magento menu
Let’s go to the first part of Lesson 6:
1. Create a Magento menu from file adminhtml.xml
• Menu Item.
<?xml version="1.0"?> <config> <menu> < module="[module name] " translate="title"> <title>[title]</title> <sort_order>[number sort order]</sort_order> <children> < module="[module name] " translate="title"> <title>[title 2]</title> <sort_order>[ number sort order] </sort_order> <action> [module adminhtml router]/adminhtml_[controller] </action> </ > <settings module="[module name] " translate="title"> <title>[title 3] </title> <sort_order>[number sort order]</</sort_order> <action>[module/controller/action] </action> </settings> </children> </> </menu>
• The meaning of tags
- <title> tag : Assign a label to the menu, displaying on horizontal navigation menu bar
- <sort_order> tag: assign sort value to each menu, by left-to-right, top-to-bottom order, defined by increasing value of sort_order value.
- <action> tag : define the controller/action that processing this menu, similar to assigning links to the menu.
• Menu displayed in backend.
For example:
File app\code\local\Magestore\Lesson06\etc\adminhtml.xml
<?xml version="1.0"?> <config> <menu> <lesson06 module="lesson06" translate="title"> <title>Lesson06</title> <sort_order>71</sort_order> <children> <lesson06 module="lesson06" translate="title"> <title>Manage Items</title> <sort_order>0</sort_order> <action> lesson06admin/adminhtml_lesson06 </action> </lesson06> <settings module="lesson06" translate="title"> <title>Settings</title> <sort_order>1000</sort_order> <action>adminhtml/system_config/edit/section/lesson06</action> </settings> </children> </lesson06> </menu>
Result :
2. Create ACL to help setting permissions to Magento menus
• Define ACL in file adminhtml.xml
For example:
<acl> <resources> <all> <title>Allow Everything</title> </all> <admin> <children> <system> <children> <config> <children> <lesson06 module="lesson06" translate="title"> <title>Lesson06</title> <sort_order>71</sort_order> </lesson06> </children> </config> </children> </system> <lesson06 module="lesson06" translate="title"> <title>Lesson06</title> <sort_order>71</sort_order> <children> <lesson06 module="lesson06" translate="title"> <title>Manage Items</title> <sort_order>0</sort_order> </lesson06> <settings module="lesson06" translate="title"> <title>Settings</title> <sort_order>1000</sort_order> </settings> </children> </lesson06> </children> </admin> </resources> </acl>
• Create roles to set permissions for users in backend
We can create roles to the new created Magento menus by accessing backend following this path:
System -> Permissions -> Roles -> Add New Role
Applying ACL Magento.
File : app\code\local\Magestore\Lesson06\controllers\Adminhtml\Lesson06Controller.php
protected function _isAllowed() { return Mage::getSingleton('admin/session')->isAllowed('lesson06'); }
• Effects of permission settings to corresponding Admin User
Without adding roles to user (as above), when a user access a Magento menu, there is a denied error message.
That is the end of part 1 – Create a Magento menu in backend.
In part 2, we will learn how to create controller action in backend.
Enjoy coding and see you later. Follow us in Magento Open Course for Magento Tutorial.
7 Comments
can I download the source code for the Lessons?
Yes, but give us a source note.
Hello sir actually Im not understand in this section? Is it we must create new module lesson 6? or we just use the already one?
Don’t really understand your question. This lesson is creating menu, not module.
Can i take the source code of these lessons please?Tutorial is great.Thank you
sure 🙂 just give us a credit by a reference link to our blog.
Does this tutorial works on the latest Magento version