Magento Custom Module Admin Permissions
I have created a few custom modules for Magento and when I try to assign permissions to the module (check the checkbox) when I click save it unchecks the box.
Anyone have any ideas? It sort of sounds like there is something off in my config.xml file so I will post it here just in case:
<config>
<modules>
<Wpe_Vendorlist>
<version>0.1.0</version>
</Wpe_Vendorlist>
</modules>
<admin>
<routers>
<vendorlist>
<use>admin</use>
<args>
<module>Wpe_Vendorlist</module>
<frontName>vendorlist</frontName>
</args>
</vendorlist>
</routers>
</admin>
<adminhtml>
<menu>
<customer>
<children>
<items module="vendorlist">
<title>SO Vendor List</title>
<sort_order>999</sort_order>
<action>vendorlist/adminhtml_vendorlist</action>
</items>
</children>
</customer>
</menu>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<Wpe_Vendorlist>
<title>Vendorlist Module</title>
<sort_order>10</sort_order>
</Wpe_Vendorlist>
</children>
</admin>
</resources>
</acl>
<layout>
<updates>
<vendorlist>
<file>vendorlist.xml</file>
</vendorlist>
</updates>
</layout>
</adminhtml>
<global>
<models>
&l开发者_JAVA百科t;vendorlist>
<class>Wpe_Vendorlist_Model</class>
<resourceModel>vendorlist_mysql4</resourceModel>
</vendorlist>
<vendorlist_mysql4>
<class>Wpe_Vendorlist_Model_Mysql4</class>
<entities>
<vendorlist>
<table>vendorlist</table>
</vendorlist>
</entities>
</vendorlist_mysql4>
</models>
<resources>
<vendorlist_setup>
<setup>
<module>Wpe_Vendorlist</module>
</setup>
<connection>
<use>core_setup</use>
</connection>
</vendorlist_setup>
<vendorlist_write>
<connection>
<use>core_write</use>
</connection>
</vendorlist_write>
<vendorlist_read>
<connection>
<use>core_read</use>
</connection>
</vendorlist_read>
</resources>
<blocks>
<vendorlist>
<class>Wpe_Vendorlist_Block</class>
</vendorlist>
</blocks>
<helpers>
<vendorlist>
<class>Wpe_Vendorlist_Helper</class>
</vendorlist>
</helpers>
</global>
</config>
I strongly recomend you to take a look at Alan Storm's article about system configuration, and the rest of his serie, it's the best info I've found about magento programing.
For this particular question, here is how I've done it in my module, with your module name:
<acl><!-- permits -->
<resources>
<admin>
<children>
<customer translate="title" module="vendorlist"><!-- this tag matches the menu tag, and the same for his children -->
<title>what will appears in the checkboxes tree when you create a role</title>
<children>
<firstchild>
<title>what will appears in the checkboxes tree when you create a role</title>
</firstchild>
</children>
</customer>
</children>
</admin>
</resources>
</acl>
You won't need the:
<children>
<firstchild>
<title>what will appears in the checkboxes tree when you create a role</title>
</firstchild>
</children>
as you don't have children in your module, it seems, I just put it as an example.
I hope this helps
Please change your config.xml and replace
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<Wpe_Vendorlist>
<title>Vendorlist Module</title>
<sort_order>10</sort_order>
</Wpe_Vendorlist>
</children>
</admin>
</resources>
</acl>
with
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<vendorlist>
<title>Vendorlist Module</title>
<sort_order>10</sort_order>
</vendorlist>
</children>
</admin>
</resources>
</acl>
Only need to change vendorlist after children tag instead of Wpe_Vendorlist. This change worked for me in my custom module,hope may help others also.
You should use only lower case characters in your resource and menu item names. See the constructor on app/code/core/Mage/Adminhtml/Block/Permissions/Tab/Rolesedit.php
public function __construct()
{
...
foreach ($rules_set->getItems() as $item) {
$itemResourceId = $item->getResource_id();
if (array_key_exists(strtolower($itemResourceId), $resources) && $item->getPermission() == 'allow') {
$resources[$itemResourceId]['checked'] = true;
array_push($selrids, $itemResourceId);
}
}
....
I would also suggest you consider moving the acl and menu info to adminhtml.xml instead of having it on config.xml.
Another issue is that you should have exactly the same structure in both menu and acl trees, so your acl reflects the menu structure and magento knows what to enable when a permission is given to a role. There's a great article by Ivan Chepurnyi about this here
So, after the changes, you would end up with someting similar to this, on adminhtml.xml:
<adminhtml>
<menu>
<customer>
<children>
<wpe_vendorlist module="vendorlist">
<title>SO Vendor List</title>
<sort_order>999</sort_order>
<action>vendorlist/adminhtml_vendorlist</action>
</wpe_vendorlist>
</children>
</customer>
</menu>
<acl>
<resources>
<all>
<title>Allow Everything</title>
</all>
<admin>
<children>
<customer>
<children>
<wpe_vendorlist>
<title>Vendorlist Module</title>
<sort_order>10</sort_order>
</wpe_vendorlist>
</children>
</customer>
</children>
</admin>
</resources>
</acl>
</adminhtml>
I found something from magento forum. Go to the following link: http://www.magentocommerce.com/boards/viewthread/78673/
But still can't set permission to these custom modules from newly created roles. These custom modules didn't appear in main menu for that newly created roles' users.
after changing syntax in acl tag module is displayed in custom module permission
精彩评论