如何在magento的自定义模块中添加ACL


8

我在magento中创建了自定义模块。我在客户菜单下创建了该菜单。我需要为自定义模块添加ACL。我需要知道如何在自定义模块中创建ACL,在这里给我我的config.xml ...

my config.xml
------------------
<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <!-- module configuration -->
    <modules>
        <Webcreon_Seller>
            <version>1.0.0</version>
        </Webcreon_Seller>
    </modules>
    <!-- module configuration end -->
    <frontend>
        <routers>
            <seller>
                <use>standard</use>
                <args>
                    <module>Webcreon_Seller</module>
                    <frontName>seller</frontName>  
                </args>
            </seller>
        </routers>
     <layout>
            <updates>
                <seller>
                      <file>sellerform.xml</file>
                </seller>
            </updates>
       </layout>
    </frontend>
    <admin>
     <routers>
         <seller>
            <use>admin</use>
            <args>
               <module>Webcreon_Seller</module>
               <frontName>adminseller</frontName>
            </args>
         </seller>
      </routers>
 </admin>
 <adminhtml>
   <layout>
      <updates>
          <seller>
              <file>sellerform.xml</file>
           </seller>
      </updates>
   </layout>
   <menu>
      <customer translate="title" module="adminhtml">

         <sort_order>100</sort_order>
         <children>
             <set_time>
                   <title>Seller List</title>
                   <action>adminseller/adminhtml_index</action>
              </set_time>
          </children>
       </customer>
    </menu>
</adminhtml> 

    <global>
        <blocks>
            <seller>
                <class>Webcreon_Seller_Block</class>
            </seller>
         </blocks>
         <helpers>
            <seller>
                <class>Webcreon_Seller_Helper</class>
            </seller> 
        </helpers>
              <models>
          <seller>
                <class>Webcreon_Seller_Model</class>
                 <resourceModel>seller_mysql4</resourceModel>
            </seller> 
            <seller_mysql4>
             <class>Webcreon_Seller_Model_Mysql4</class>
             <entities>
                 <seller>
                   <table>db_vendor</table>
                 </seller>
              </entities>
          </seller_mysql4>
        </models>
        <resources>
        <!-- connection to write -->
        <seller_write>
            <connection>
                <use>core_write</use>
            </connection>
        </seller_write>
        <!-- connection to read -->
       <seller_read>
          <connection>
             <use>core_read</use>
          </connection>
       </seller_read>
       <webcreon_seller_setup>
            <setup>
                <module>Webcreon_Seller</module>
            </setup>
        </webcreon_seller_setup>
</resources>
<rewrite>
    <sellercreate>
         <from><![CDATA[#^/seller[\/]?$#]]></from>
         <to><![CDATA[/seller/seller/sellercreate/$1]]></to>
         <complete>1</complete>
      </sellercreate>
</rewrite>
</global>


</config>

Answers:


3

adminhtml.xmlWebcreon/Seller/etc需要的地方创建代码

<?xml version="1.0" encoding="UTF-8" ?>
    <config>
        <acl>
          <resources>
            <all>
              <title>Allow Everything</title>
            </all>
            <admin>
             <children>
                <customer translate="title" module="seller">
                  <children>
                    <set_time translate="title">
                    <title>Seller List</title>
                    </set_time>
                  </children>
                </customer>
              </children>
            </admin>
          </resources>
        </acl>
    </config>

根据您的意愿,创建new menu at customer section了一个child tab名称为 set_time 所以我要添加此代码

    <customer translate="title" module="seller">
      <children>
        <set_time translate="title">
        <title>Seller List</title>
        </set_time>
      </children>
    </customer>

我需要在客户ACL组中显示我的模块。.意味着我在客户部分的允许下
Deepak Kumar,

是。在客户
眼中

其未在“客户”部分下显示..也未在ACL组中显示
Deepak Kumar

我在etc ...中创建了adminhtml ...但是您将整个代码粘贴到了文件中...我删除了缓存...然后在admin中重新登录...但是在用户权限中它没有显示
Deepak Kumar

确保从缓存管理页面中单击“刷新缓存存储”。“刷新Magento缓存”不会更新它。
艾默里·金

10

一般说明:

管理员菜单的ACL

要为自定义管理菜单项定义ACL ,请将以下所有内容复制adminhtml/menuacl/resources/admin/children并删除<action>节点。

示例:复制内容

http://i.stack.imgur.com/9CiIQ.png

要实际使用ACL,您必须向控制器添加以下方法:

protected function _isAllowed()
{
    return Mage::getSingleton('admin/session')->isAllowed('ENTER RESOURCE IDENTIFIER HERE');
}

资源标识符基于下面的节点名acl/resources/admin/children,跳过后面的children节点。

示例:资源标识符

http://i.stack.imgur.com/HZ2Is.png

系统配置的ACL部分

要为系统配置部分定义ACL ,必须在下面添加以下内容acl/resources/admin/children

<system>
  <children>
    <config>
      <children>
        <my_configuration_section>
          <title>My Configuration Section</title>
        </my_configuration_section>
      </children>
    </config>
  </children>
</system>

my_configuration_section来自哪里system.xml

<sections>
    <my_configuration_section translate="label" module="my_module">
      ...
    </my_configuration_section>
</sections>     

针对您的问题:

在您的情况下,这意味着adminhtml.xml应如下所示:

<?xml version="1.0" encoding="UTF-8" ?>
<config>
    <acl>
      <resources>
        <admin>
         <children>

           <customer translate="title" module="adminhtml">
             <sort_order>100</sort_order>
             <children>
               <set_time>
                 <title>Seller List</title>
               </set_time>
             </children>
           </customer>

          </children>
        </admin>
      </resources>
    </acl>
</config>
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.