Magento - Admin URL 显示前端 404(自定义模块)

Magento - Admin URL Shows Front End 404 (Csutom Module)

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

我是来为模块创建管理区的,遇到了很多麻烦。 当我单击我的模块的菜单项(目录 > 报告的产品)时,它会呈现网站的前端。 (url 和预期的一样 "domain.com/index.php/admin/reported_products/adminhtml/key/76f4724a69.../")。这会显示一个 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.

中的 <action> 节点

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

如果我在操作前加上 adminhtml,它会呈现前端页眉和页脚,但会转到正确的 url“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();
    }
}

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

尝试

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

使您的菜单 link 看起来像这样:

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

或者更好的是,将您的管理路由器声明为 R.S 描述 ,在这种情况下,您需要将控制器从 Tbe/Report/controllers/Adminhtml/IndexController.php 移动到 Tbe/Report/controllers/Adminhtml/Reported/IndexController.php(更改class 也相应地命名),你可以有你的菜单 link 这样的:

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