创建模块
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攻击。