簡體   English   中英

Magento自定義模塊管理員權限

[英]Magento Custom Module Admin Permissions

我為Magento創建了一些自定義模塊,當我嘗試為模塊分配權限時(選中復選框),當我單擊“保存”時,取消選中該框。

有人有想法么? 聽起來有點像我的config.xml文件中的內容,所以我會在這里發布以防萬一:

<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>
        <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>

我強烈建議你看一下Alan Storm關於系統配置的文章 ,以及他的其他系列,這是我發現的有關magento編程的最佳信息。

對於這個特殊的問題,以下是我在模塊中使用您的模塊名稱完成的方法:

<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>

你不需要:

                <children>
                    <firstchild>
                        <title>what will appears in the checkboxes tree when you create a role</title>
                    </firstchild>
                </children>

因為你的模塊里沒有孩子,看來,我只是把它作為一個例子。
我希望這有幫助

請更改您的config.xml並替換

<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>

<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>

只需要在子標簽后更改vendorlist而不是Wpe_Vendorlist。 這個改變在我的自定義模塊中對我有用,希望也可以幫助別人。

您應該只在資源和菜單項名稱中使用小寫字符。 請參閱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);
        }
    }

    ....

我還建議你考慮將acl和菜單信息移到adminhtml.xml而不是在config.xml上。

另一個問題是你應該在菜單和acl樹中具有完全相同的結構,因此你的acl反映了菜單結構,magento知道在給角色許可時要啟用什么。 Ivan Chepurnyi在這里發表了一篇很棒的文章

因此,在更改之后,您最終會在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>

更改acl標記模塊中的語法后,在自定義模塊權限中顯示

我從magento論壇找到了一些東西。 請訪問以下鏈接: http//www.magentocommerce.com/boards/viewthread/78673/

但仍無法從新創建的角色中為這些自定義模塊設置權限。 這些自定義模塊未顯示在新創建的角色用戶的主菜單中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM