【问题标题】:Magento custom tab and admin controller aclMagento 自定义选项卡和管理控制器 acl
【发布时间】:2012-09-11 06:02:09
【问题描述】:

我对用于管理后端的自定义控制器 ACL 有疑问。 我已经阅读,重新阅读,检查......但仍然找不到我的问题。该死。

首先,代码...模块本身正在运行...我有块、助手、前端控制器...系统->配置选项卡/组数据...一切正常。我的问题只是与 admincontroller acl 有关...所以我现在只添加该区域的相关代码。

我的后端选项卡正在显示,但网址(admin/mynewmodule/index、admin/mynewmodule/list)转到 404 页面。

config.xml,管理路由器:

 <admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <mynewmodule before="Mage_Adminhtml">
                        Mworkz_MyNewModule_Adminhtml
                    </mynewmodule >
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

Adminhtml.xml、后端选项卡和 acl

 <?xml version="1.0"?>
 <config>
 <menu>
    <mynewmodule module="mynewmodule " translate="title">
        <title>MyNewModule</title>
        <sort_order>71</sort_order>               
            <children>
                    <items module="mynewmodule " translate="title">
                        <title>Index Action</title>
                        <sort_order>1</sort_order>
                        <action>adminhtml/mynewmodule/</action>
                    </items>
                    <list module="mynewmodule " translate="title">
                        <title>List Action</title>
                        <sort_order>2</sort_order>
                        <action>adminhtml/mynewmodule/list/</action>
                    </list>
             </children>
    </mynewmodule >
</menu>

    <acl>
        <resources>
            <admin>
                <children>
                    <system>
                        <children>
                            <config>
                                <children>
                                    <mynewmodule translate="title">
                                            <title>MyNewModule</title>
                                    </mynewmodule>
                                </children>
                            </config>
                        </children>
                    </system>
                    <mynewmodule translate="title" module="mynewmodule">
                    <title>MyNewModule</title>
                        <sort_order>-100</sort_order>
                        <children>
                            <items translate="title">
                                <title>Index Action</title>
                                <sort_order>1</sort_order>
                            </items>
                            <list translate="title">
                                <title>List Action</title>
                                <sort_order>2</sort_order>
                            </list>
                        </children>
                    </mynewmodule>
                </children>
            </admin>
        </resources>
    </acl>
    <layout>
        <updates>
            <mynewmodule>
                <file>mworkz/mynewmodule.xml</file>
            </mynewmodule>
        </updates>
    </layout>

 </config>

管理员控制器

 class Mworkz_MyNewModule_Adminhtml_MyNewModuleController extends Mage_Adminhtml_Controller_action
 {

protected function _initAction() {

    $this->loadLayout()
        ->_setActiveMenu('extbuilderpro/items')
        ->_addBreadcrumb(Mage::helper('adminhtml')->__('Items Manager'), Mage::helper('adminhtml')->__('Item Manager'));

    return $this;
}   

public function indexAction() {

    $this->_initAction()
        ->renderLayout();
}

 public function listAction() {

    $this->_initAction()
        ->renderLayout();
}

 }

【问题讨论】:

  • 在测试更改后,我也一直在清除我的“会话”和“缓存”目录。
  • adminhtml/mynewmodule / - 来自哪里的空格
  • 另外...我的前端控制器路由是:/mynewmodule/index 我的后端路由是:/admin/mynewmodule/index 考虑到后端的管理员前缀,这些不能/不会发生冲突吗?
  • 如果你自己写扩展,路径必须是module_name/admin_html/list。下载免费的 magento 扩展,例如:magentocommerce.com/magento-connect/… 并查看etc/config.xml

标签: magento controller admin acl


【解决方案1】:

如果您编写自己的扩展,路径必须是module_name/admin_html/list。下载免费的 magento 扩展,例如:http://www.magentocommerce.com/magento-connect/news-by-commercelab-3436.html 并查看 etc/config.xml。

正确的代码:

<menu>
    <modulename module="modulename" translate="title">
        <title>Module Name</title>
        <sort_order>1</sort_order>
        <children>
            <add translate="title" module="modulename">
                <title>Add New Item</title>
                <sort_order>0</sort_order>
                <action>modulename/adminhtml_news/new</action>
            </add>
            <items translate="title" module="modulename">
                <title>Items Manager</title>
                <sort_order>10</sort_order>
                <action>modulename/adminhtml_news/index</action>
            </items>
            <settings translate="title" module="modulename">
                <title>Settings</title>
                <sort_order>40</sort_order>
                <action>adminhtml/system_config/edit/section/modulename</action>
            </settings>
        </children>
    </clnews>
</menu>

【讨论】:

  • "path must be module_name/admin_html/list" 不是一个正确的陈述(因为“must”这个词)。这个可以是路径,但要由配置决定。
  • @benmarks 是对的。如果上述答案正确,则表示配置已更改。在最初的问题上,配置使用路由器的before 参数。看起来最初的问题是由&lt;mynewmodule before="Mage_Adminhtml"&gt; Mworkz_MyNewModule_Adminhtml &lt;/mynewmodule &gt; 之间的空格引起的。你怎么看?
  • 感谢您的解释。我可以在哪里阅读更多相关信息? (如果我的问题在这个话题中被接受)。
  • @doktorgradus "Shaun UUDotCom" 使用这个方法:web-magician.blogspot.com/2009/04/… 这样路由器仍然使用adminhtml 而不是定义自己的路由器(在你的回答中是modulename
  • 谢谢,我在前一段代码中有“使用”标签...在调整/重写后忘记移动了。现在我知道为什么需要了:)
猜你喜欢
  • 1970-01-01
  • 2016-10-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多