13. Magento 后台top栏开发(二)

创建模块
这里写图片描述

adminhtml.xml

<config>
    <menu>
        <second_top translate="title" module="second">
            <title>Second_Top</title>
            <sort_order>999</sort_order>

            <children>
                <second_111 translate="title">
                    <title>Second_111</title>
                    <sort_order>1</sort_order>
                </second_111>

                <second_222 translate="title">
                    <title>Second_222</title>
                    <sort_order>2</sort_order>
                </second_222>
            </children>
        </second_top>
    </menu>
</config>
These attribute tell Magento the <title/> node should be translated by the Mage::helper('pulsestorm_adminhello')->__($string) helper method. Because of this, we’ll need to add a standard data helper to our module.

To do so, make sure your module’s config.xml (not adminhtml.xml) includes the following definition for helper classes

启用助手类

config.xml

<config>
    <global>
        <helpers>
            <second>
                <class>Www_Second_Helper</class>
            </second>
        </helpers>
    </global>
</config>
Data.php

<?php
class Www_Second_Helper_Data extends Mage_Core_Helper_Abstract
{
}

刷新后台
这里写图片描述


Menu Acl 权限
先看看如下文件:

#File: app/code/core/Mage/Adminhtml/Block/Page/Menu.php
protected function _buildMenuArray(Varien_Simplexml_Element $parent=null, $path='', $level=0)
{
    <!-- ... -->
    foreach ($parent->children() as $childName => $child) {
        if (1 == $child->disabled) {
            continue;
        }

        $aclResource = 'admin/' . ($child->resource ? (string)$child->resource : $path . $childName);
        if (!$this->_checkAcl($aclResource)) {
            continue;
        }
    <!-- ... main loop body ... -->
}

这个循环检查所有< menu>下的节点,并用节点名称来创建ACL资源路径。

#File: app/code/core/Mage/Adminhtml/Block/Page/Menu.php    
$aclResource = 'admin/' . ($child->resource ? (string)$child->resource : $path . $childName);
and then runs an ACL check on each node.

#File: app/code/core/Mage/Adminhtml/Block/Page/Menu.php        
if (!$this->_checkAcl($aclResource)) {
    continue;
}
如果检查失败,magent跳过这个迭代循环的继续,(换句话说,该菜单项的渲染而被跳过)
在我们的例子中ACL路径是:
admin/second_top
admin/second_top/second_111
admin/second_top/second_222

添加ACL权限:

adminhtml.xml

<config>
    <menu>
        <second_top translate="title" module="second">
            <title>Second_Top</title>
            <sort_order>999</sort_order>

            <children>
                <second_111 translate="title">
                    <title>Second_111</title>
                    <sort_order>1</sort_order>
                </second_111>

                <second_222 translate="title">
                    <title>Second_222</title>
                    <sort_order>2</sort_order>
                </second_222>
            </children>
        </second_top>
    </menu>

    <acl>
        <resources>
            <admin>
                <children>
                    <second_top translate="title" module="second">
                        <title>second_top</title>
                        <sort_order>1</sort_order>

                        <children>
                            <second_111 translate="title">
                                <title>second_111</title>
                                <sort_order>1</sort_order>
                            </second_111>

                            <second_222 translate="title">
                                <title>second_222</title>
                                <sort_order>2</sort_order>
                            </second_222>
                        </children>
                    </second_top>
                </children>
            </admin>
        </resources>
    </acl>
</config>

在添加Role中可以看到:
这里写图片描述

注意::ACL资源是缓存PHP会话对象。这意味着它常常需要登录和注销才可以看到ACL资源视图的变化相关。

创建路由
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述
这里写图片描述


Magento Front Name Sharing
这里写图片描述
这里写图片描述
这里写图片描述


Magento Admin URLs

这里写图片描述

这是一个临时添加到每个magent的URL。这有助于保护系统受到CSFR攻击。

这里写图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值