问题描述:

I am creating a Magento module to allow products to be reported.

I have done the front end okay and all is working there.

I have come to create an admin area for the module and am having a lot of trouble.

When I click on the menu item for my module (Catalog > Reported Products), it renders the front end of the website. (The url is as expected though "domain.com/index.php/admin/reported_products/adminhtml/key/76f4724a69.../"). This displays a 404 page.

I've tried a lot of variations on the action of the menu item but nothing has worked.

I've also changed the front_name under the admin node, but nothing :/

I'll try to present the files in a nice order...

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();

}

}

Yes, I do have a blank Data.php under Tbe/Report/Helpers/

Any and all help is appreciated.

UPDATE

I have managed to get it working (somewhat).

The only issue now is the <action> node in adminhtml.xml.

If I DO NOT prepend the action with adminhtml, the page renders, showing the admin header and footer (I haven't done any content yet). However, the URL does not contain /admin. Instead, the URL is "http://domain.com/index.php/reported_products/reported/key/88bf4.../".

If I do prepend the action with adminhtml, It renders the front end header and footer but goes to the correct url "http://domain.com/index.php/admin/reported_products/reported/key/88bf4.../".

I would really like for the URL to be with /admin. Here's my updated code:

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();

}

}

网友答案:

Since your controller is in /Tbe/Report/controllers/Adminhtml/IndexController.php and not /Tbe/Report/controllers/IndexController.php therefore you need to use <Tbe_Report after="Mage_Adminhtml">Tbe_Report_Adminhtml<...

Try

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

Assuming the following folder structure.

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

Menu

<action>adminhtml/reported/index/</action>
网友答案:

Make your menu link look like this:

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

or better yet, declare your admin router as R.S described in an other answer and in this case you need to move your controller from Tbe/Report/controllers/Adminhtml/IndexController.php to Tbe/Report/controllers/Adminhtml/Reported/IndexController.php (change the class name accordingly also) and you can have your menu link like this:

<action>adminhtml/reported/index</action>
相关阅读:
Top