【问题标题】:Magento - Admin URL Shows Front End 404 (Csutom Module)Magento - 管理 URL 显示前端 404(自定义模块)
【发布时间】:2015-10-03 05:08:41
【问题描述】:

我正在创建一个 Magento 模块来允许报告产品。 我已经做好了前端,一切都在那里工作。

我来为模块创建一个管理区域,但遇到了很多麻烦。 当我单击我的模块的菜单项(目录 > 报告的产品)时,它会呈现网站的前端。 (虽然“domain.com/index.php/admin/reported_products/adminhtml/key/76f4724a69.../”,但 url 符合预期)。这将显示一个 404 页面。

我在菜单项的操作上尝试了很多变体,但都没有奏效。 我还更改了admin 节点下的front_name,但没有:/

我会尽量把文件排列整齐……

app/code/local/Tbe/Report/etc/config.xml

<modules>
    <Tbe_Report>
        <version>0.1.0</version>
    </Tbe_Report>
</modules>

<global>

    <helpers>
        <report>
            <class>Tbe_Report_Helper</class>
        </report>
    </helpers>

    <blocks>
        <report>
            <class>Tbe_Report_Block</class>
        </report>
    </blocks>


    <models>

        <report>
            <class>Tbe_Report_Model</class>
            <resourceModel>report_mysql4</resourceModel>
        </report>

        <report_mysql4>
            <class>Tbe_Report_Model_Mysql4</class>
            <entities>
                <report>
                    <table>report</table>
                </report>
            </entities>
        </report_mysql4>

    </models>


    <resources>

        <report_setup>
            <setup>
                <module>Tbe_Report</module>
            </setup>
            <connection>
                <use>core_setup</use>
            </connection>
        </report_setup>

        <report_write>
            <connection>
                <use>core_write</use>
            </connection>
        </report_write>

        <report_read>
            <connection>
                <use>core_read</use>
            </connection>
        </report_read>

    </resources>

</global>


<frontend>

    <routers>
        <report>
            <use>standard</use>
            <args>
                <module>Tbe_Report</module>
                <frontName>report</frontName>
            </args>
        </report>
    </routers>

    <layout>
        <updates>
            <report>
                <file>report.xml</file>
            </report>
        </updates>
    </layout>  

</frontend>



<adminhtml>

    <routers>
        <report>
            <use>admin</use>
            <args>
                <module>Tbe_Report</module>
                <frontName>reported_products</frontName>
            </args>
        </report>
    </routers>

   <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Tbe_Report after="Mage_Adminhtml">Tbe_Report</Tbe_Report>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>

</adminhtml>

app/code/local/Tbe/Report/etc/adminhtml.xml

<?xml version="1.0"?>
    <config>
        <menu>
            <catalog translate="title" module="report">
                <title>Catalog</title>
                <sort_order>30</sort_order>
                <children>
                    <report>
                        <title>Reported Products</title>
                        <sort_order>100</sort_order>
                        <action>adminhtml/reported_products/reported/</action>
                    </report>
                </children>
            </catalog>
        </menu>

        <acl>
            <resources>
                <admin>
                    <children>                
                        <tbe translate="title" module="report">
                            <title>View Reported Products</title>
                            <sort_order>1</sort_order>
                        </tbe>
                    </children>
                </admin>
            </resources>
        </acl>

    </config>

app/code/core/local/Tbe/Report/controllers/ReportedController.php

class Tbe_Report_ReportedController extends Mage_Adminhtml_Controller_Action {

    public function indexAction() {

        $this->loadLayout();
        $this->renderLayout();

    }

}

是的,我在 Tbe/Report/Helpers/ 下确实有一个空白 Data.php

感谢任何和所有的帮助。

更新

我已经设法让它工作(有点)。 现在唯一的问题是 adminhtml.xml 中的 &lt;action&gt; 节点。

如果我没有在操作前添加adminhtml,页面将呈现,显示管理页眉和页脚(我还没有完成任何内容)。但是,该 URL 不包含 /admin。相反,URL 是“http://domain.com/index.php/reported_products/reported/key/88bf4.../”。

如果我在操作前添加adminhtml,它会呈现前端页眉和页脚,但会转到正确的网址“http://domain.com/index.php/admin/reported_products/reported/key/88bf4.../”。

我真的希望 URL 包含在 /admin 中。这是我更新的代码:

app/code/local/Tbe/Report/etc/config.xml

<?xml version="1.0"?>
<config>

...

<!-- NOTHING HAS CHANGED HERE -->
<!-- I HAVE GOTTEN RID OF THE <adminhtml> NODE -->


<frontend>

    <routers>
        <report>
            <use>standard</use>
            <args>
                <module>Tbe_Report</module>
                <frontName>report</frontName>
            </args>
        </report>
    </routers>

    <layout>
        <updates>
            <report>
                <file>report.xml</file>
            </report>
        </updates>
    </layout>  

</frontend>


<admin>

    <routers>
        <tbe_report>
            <use>admin</use>
            <args>
                <module>Tbe_Report</module>
                <frontName>reported_products</frontName>
                <modules>
                    <Tbe_Report after="Mage_Adminhtml">Tbe_Report_Reported</Tbe_Report>
                </modules>
            </args>
        </tbe_report>
    </routers>

</admin>

</config>

app/code/local/Tbe/Report/etc/adminhtml.xml

<?xml version="1.0"?>
<config>
<menu>
    <catalog translate="title" module="report">
        <title>Catalog</title>
        <sort_order>30</sort_order>
        <children>
            <report>
                <title>Reported Products</title>
                <sort_order>100</sort_order>
                <action>adminhtml/reported_products/reported/index</action>
            </report>
        </children>
    </catalog>
</menu>

...

</config>

app/code/local/Tbe/Report/controllers/ReportedController.php

class Tbe_Report_ReportedController extends Mage_Adminhtml_Controller_Action {

    public function indexAction() {
        $this->loadLayout();
        $this->renderLayout();
    }
}

【问题讨论】:

    标签: php xml magento magento-1.9


    【解决方案1】:

    由于您的控制器位于 /Tbe/Report/controllers/Adminhtml/IndexController.php 而不是 /Tbe/Report/controllers/IndexController.php 因此您需要使用&lt;Tbe_Report after="Mage_Adminhtml"&gt;Tbe_Report_Adminhtml&lt;...

    试试

    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Tbe_Report after="Mage_Adminhtml">Tbe_Report_Adminhtml</Tbe_Report>
                    </modules>
                </args>
            </adminhtml>
    

    假设以下文件夹结构。

    app/code/local/Tbe/Report/controllers/Adminhtml/ReportedController.php
    

    菜单

    <action>adminhtml/reported/index/</action>
    

    【讨论】:

    • 我现在已将文件 Adminhtml/IndexController.php 移动到 ReportedController.php 以防止混淆。我需要将其更改为 Tbe_Report_Reported 吗?
    • 如果它在根控制器文件夹中,那么它应该只是 Tbe_Report
    • 由于您使用的是 Mage_Adminhtml,因此中的操作也应以 adminhtml 开头。看看stackoverflow.com/a/16510952/1191288
    • 我对那个链接不太满意。他并没有很好地解释它。我的 URL 不包含 /admin 是否重要?
    • 有两种方法可以在 magento 中创建管理模块,而且您似乎正在混合使用它们。您应该做的唯一更改是我上面列出的更改,它应该可以工作。
    【解决方案2】:

    让你的菜单链接看起来像这样:

    <action>reported_products/adminhtml/index</action>
    

    或者更好的是,将您的管理路由器声明为 RS 描述的in an other answer,在这种情况下,您需要将您的控制器从 Tbe/Report/controllers/Adminhtml/IndexController.php 移动到 Tbe/Report/controllers/Adminhtml/Reported/IndexController.php(也相应地更改类名)并且您可以获得菜单链接像这样:

    <action>adminhtml/reported/index</action>
    

    【讨论】:

    • 您的建议都没有奏效。如果在操作开始时没有 adminhtml,则 url 不包含管理 URL。注意:我已经把controllers/Adminhtml/IndexController.php的位置和名字改成了controllers/ReportedController.php
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-06
    • 2013-10-06
    • 2015-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多