我正在创建一个Magento模块,以允许报告产品。我已经完成了前端,一切正常。
我来为模块创建一个管理区域,遇到了很多麻烦。当我单击模块的菜单项(Catalog> Reported Products)时,它会呈现网站的前端。(网址是预期的,虽然"domain.com/index.php/admin/reported_products/adminhtml/key/76f4724a69.../")。这将显示一个404页面。
我在菜单项的动作上尝试了很多变化,但都不起作用。我还更改了admin
节点下的front_name
,但没有更改:/
我会尽量把这些文件按顺序排列好…
app/代码/地方/此种/报告/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/代码/地方/此种/报告/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/代码/核心/地方/此种/报告/控制器/ReportedController.php
class Tbe_Report_ReportedController extends Mage_Adminhtml_Controller_Action {
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
}
是的,我有一个空白的Data.php在/Report/Helpers/
感谢所有的帮助。
我已经设法使它工作(在某种程度上)。现在唯一的问题是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/代码/地方/此种/报告/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/代码/地方/此种/报告/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>
应用程序/代码/地方/此种/报告/控制器/ReportedController.php
class Tbe_Report_ReportedController extends Mage_Adminhtml_Controller_Action {
public function indexAction() {
$this->loadLayout();
$this->renderLayout();
}
}
因为你的控制器在/the/Report/controllers/Adminhtml/IndexController.php而不是/the/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>
让你的菜单链接看起来像这样:
<action>reported_products/adminhtml/index</action>
或者更好的是,将你的管理路由器声明为另一个答案中描述的R.S,在这种情况下,你需要将控制器从Tbe/Report/controllers/Adminhtml/IndexController.php
移动到Tbe/Report/controllers/Adminhtml/Reported/IndexController.php
(也相应地改变类名),你可以像这样拥有你的菜单链接:
<action>adminhtml/reported/index</action>