【发布时间】: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 中的 <action> 节点。
如果我没有在操作前添加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