Leon Lai
Leon Lai

Reputation: 33

Magento - Can't Save Role Resource for Custom Module

I’ve created a custom module and my config.xml is as follows…

<?xml version="1.0"?>
  <config>
   <admin>
    <routers>
        <blacklist>
            <use>admin</use>
            <args>
                <module>Leon_Blacklist</module>
                <frontName>blacklist</frontName>
            </args>
        </blacklist>
    </routers>
</admin>
<adminhtml>
    <menu>
        <blacklist translate="title" module="blacklist">
            <title>Blacklist</title>
            <sort_order>71</sort_order>               
            <children>
                <items translate="title" module="blacklist">
                    <title>Manage Items</title>
                    <sort_order>0</sort_order>
                    <action>blacklist/adminhtml_blacklist</action>
                </items>
            </children>
        </blacklist>
    </menu>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
            <admin>
                <children>
                    <Leon_Blacklist translate="title" module="blacklist">
                        <title>Blacklist Module</title>
                        <sort_order>10</sort_order>

                        <children>
                            <items translate="title" module="blacklist">
                                <title>Manage Items</title>
                            </items>                        
                        </children>
                    </Leon_Blacklist>
                </children>
            </admin>
        </resources>
    </acl>
    <layout>
        <updates>
            <blacklist>
                <file>blacklist.xml</file>
            </blacklist>
        </updates>
    </layout>
</adminhtml> 
<config>

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 login using the account with the said user role, the custom module is hidden. What seems to be the problem? Any kind of help is much appreciated..

Thanks.

Upvotes: 2

Views: 3136

Answers (2)

Chandresh
Chandresh

Reputation: 371

Here is my acl section of config.xml

<acl>
    <resources>
        <all>
            <title>Allow Everything</title>
        </all>
        <admin>
            <children>
                <banner translate="title" module="banner">
                    <title>Banner Module</title>
                    <sort_order>10</sort_order>
                    <children>
                        <banner translate="title" module="banner">
                            <title>Manage Banners</title>
                        </banner>                      
                    </children>
                </banner>
            </children>
        </admin>
    </resources>
</acl>

Also add the below function in your controller to avoid the "Access denied" message

protected function _isAllowed(){
        return true;
}

Code taken from: http://chandreshrana.blogspot.in/2015/06/custom-module-role-not-save-in.html

Upvotes: 0

Alexei Yerofeyev
Alexei Yerofeyev

Reputation: 2103

Your acl section of config is a little wrong. Tags should be similar to menu section. So in your case it should look like this:

<acl>
    <resources>
        <admin>
            <children>
                <blacklist translate="title" module="blacklist">
                    <title>Blacklist Module</title>
                    <sort_order>10</sort_order>

                    <children>
                        <items translate="title" module="blacklist">
                            <title>Manage Items</title>
                        </items>                        
                    </children>
                </blacklist>
            </children>
        </admin>
    </resources>
</acl>

Upvotes: 5

Related Questions