我已经创建了一个自定义模块, 在目录中添加了两个菜单。我还为其中一个菜单创建了控制器,但控制器从未被调用,而是被重定向到管理仪表板页面。
我的问题是与这个问题有关的Magento管理路由不工作
我尝试了答案中提到的建议,但没有一个对我有效。
每当我调用url http://localhost/compare/index.php/ecomm/index/key/bb9f436ee373421b170aa862a1cbb305/
我被重定向到http://localhost/compare/index.php/admin/dashboard/index/key/bb9f436ee373421b170aa862a1cbb305/,并且hello world永远不会被打印出来。
我正在使用magento 1.9,并已禁用所有缓存。
我的模块名是Super_Awesome下面是目录结构
<>以前超级||太棒了|-etc (adminhtml.xml, config.xml)|控制器(ManageEcomm.php)|助手(Data.php)之前app/etc/modules/Super_Awesome.xml中的配置文件如下
<?xml version="1.0"?>
<config>
<modules>
<Super_Awesome>
<active>true</active>
<codePool>local</codePool>
</Super_Awesome>
</modules>
</config>
app/code/local/Super/Awesome/etc/config.xml中的配置文件是
<?xml version="1.0"?>
<config>
<modules>
<Super_Awesome>
<version>0.1.0</version>
</Super_Awesome>
</modules>
<admin>
<routers>
<ecomm>
<use>admin</use>
<args>
<module>Super_Awesome</module>
<frontName>ecomm</frontName>
</args>
</ecomm>
</routers>
</admin>
<adminhtml>
<!-- The <acl> section is for access control. Here we define the pieces where access can be controlled within a role. -->
<acl>
<resources>
<admin>
<children>
<catalog>
<!--<title>Awesome Menu Item</title>-->
<children>
<example translate="title" module="awesome">
<title>Manage Ecommerce</title>
</example>
<example1 translate="title" module="awesome">
<title>Manage Ecommerce Pages</title>
</example1>
</children>
</catalog>
</children>
</admin>
</resources>
</acl>
</adminhtml>
<global>
<helpers>
<awesome>
<class>Super_Awesome_Helper</class>
</awesome>
</helpers>
</global>
</config>
控制器应用程序/代码/地方/超级/棒/控制器/IndexController.php
<?php
class Super_Awesome_IndexController extends Mage_adminhtml_Controller_Action
{
public function indexAction()
{
echo "hello world";
exit();
}
}
最后的adminhtml.xml文件在app/code/local/Super/Awesome/etc/
<?xml version="1.0"?>
<config>
<menu>
<catalog translate="title" module="awesome">
<!--<title>Awesome</title>
<sort_order>15</sort_order>-->
<children>
<example translate="title" module="awesome">
<title>Manage Ecommerce</title>
<sort_order>1</sort_order>
<action>adminhtml/ecomm</action>
</example>
<example1 translate="title" module="awesome">
<title>Manage Ecommerce Pages</title>
<sort_order>2</sort_order>
<action>adminhtml/example/index</action>
</example1>
</children>
</catalog>
</menu>
</config>
我想你已经错过了在etc/config.xml
中添加新模块作为adminhtml
路由器的部分。应该是这样的:
当Magento试图找到一个管理URL的控制器文件时,它也会检查在这个
<modules/>
标签内配置的任何模块。
<config>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<Super_Awesome after="Mage_Adminhtml">Super_Awesome</Super_Awesome>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
我终于发现自己创建一个模块并不好。如果你犯了一个错误,你可能会浪费你宝贵的时间去寻找出错的地方。
最好从Ultimate module creator中安装模块创建器扩展,或者使用Silk提供的在线工具