Can’t Save Role Resource for Custom Module – Magento 1 Solution

modulerole

I've created a custom module and my adminhtml.xml is as follows…

<config>
<menu>
    <web translate="title" module="adminhtml">
        <title>Custom</title>
        <sort_order>110</sort_order>
        <children>
            <web>
                <title>User Info</title>
                <action>web/adminhtml_web</action>
            </web>
        </children>
    </web>
</menu>
<acl>
    <resources>
        <admin>
            <children>
                <Company_Web>
                    <title>Custom</title>
                    <sort_order>60</sort_order>
                    <children>
                        <web>
                            <title>User Info</title>
                            <action>web/adminhtml_web</action>
                        </web>
                    </children>
               </Company_Web>
           </children>
       </admin>
   </resources>
</acl>

The module works as expected if an admin account is logged in. I can see the module in the admin panel and in the Role Resource Tab (System->Permissions->Roles), but when I tried to check the module and save the user role, it will say that it has been saved. But when I rechecked the user role, it is still unchecked.

And when I tried to log in using the account with the said user role, the custom module is hidden. What seems to be the problem?

Best Answer

The problem here is that your resource has to match the menu name. This is a convention in Magento and if you do not do this, then it will show, but you cannot save the values. This is a problem I faced often before.

Here is a simple example of how it should work:

<?xml version="1.0" ?>
<config>
    <menu>
        <mycustom_menu translate="title" module="YOUR_MODULE_NAME">
            <title>My Menu</title>
            <sort_order>100</sort_order>
            <children>
                <!-- children -->
                <subitem translate="title" module="YOUR_MODULE_NAME">
                    <title>Subitem</title>
                    <sort_order>10</sort_order>
                    <action>adminhtml/mycustom_controller/</action>
                </subitem>
            </children>
        </mycustom_menu>
    </menu>
    <acl>
        <resources>
            <admin>
                <children>
                    <mycustom_menu translate="title" module="YOUR_MODULE_NAME">
                        <title>My Menu</title>
                        <sort_order>300</sort_order>
                        <children>
                            <!-- children -->
                            <subitem translate="title" module="YOUR_MODULE_NAME">
                                <title>Subitem</title>
                                <sort_order>10</sort_order>
                            </subitem>
                        </children>
                    </mycustom_menu>
                </children>
            </admin>
        </resources>
    </acl>
</config>

EDIT: Also have a look here for a great tutorial of system configuration and ACL http://alanstorm.com/custom_magento_system_configuration

Related Topic