Magento管理员路由不起作用 [英] Magento admin routing isn't working
问题描述
我正在为Magento的管理区域开发一个模块.我正在尝试在 Magento管理控制器上遵循Alan Storm的教程,但似乎无法让我的控制器执行此操作任何事物.我认为它可能有一些做路由,但我不知道.它显示了带有404错误的前端模板.
I'm working on a module for the admin area of Magento. I'm trying to follow Alan Storm's tutorial on Magento admin controllers but can't seem to get my controller to do anything. I think it may have something to do with routing, but I'm not sure. It shows me the frontend template with a 404 error.
(注意:我已经在此处包括了所有相关代码.实际问题在最底部.)
该模块称为Mynamespace_Donor,位于app/code/local/Mynamespace/Donor/中.
The module is called Mynamespace_Donor and lives in app/code/local/Mynamespace/Donor/.
我等/config.xml中看起来像这样:
My etc/config.xml looks like this:
<?xml version="1.0"?>
<config>
<modules>
<Mynamespace_Donor>
<version>0.1.0</version>
</Mynamespace_Donor>
</modules>
<global>
<helpers>
<donor>
<class>Mynamespace_Donor_Helper</class>
</donor>
</helpers>
<resources>
<donor_setup>
<setup>
<module>Mynamespace_Donor</module>
</setup>
</donor_setup>
</resources>
</global>
<admin>
<routers>
<donor>
<use>admin</use>
<args>
<module>Mynamespace_Donor</module>
<frontname>donor</frontname>
</args>
</donor>
</routers>
</admin>
<adminhtml>
<menu>
<donor translate="title" module="donor">
<title>Donor</title>
<sort_order>42</sort_order>
<children>
<manage_donors module="donor">
<title>Manage Donors</title>
<action>donor/index/index</action>
</manage_donors>
</children>
</donor>
</menu>
</adminhtml>
</config>
我的controllers/IndexController.php看起来像这样:
And my controllers/IndexController.php looks like this:
<?php
class Mynamespace_Donor_IndexController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->loadLayout();
//create a text block with the name of "example-block"
$block = $this->getLayout()
->createBlock('core/text', 'example-block')
->setText('<h1>This is a text block</h1>');
$this->_addContent($block);
$this->renderLayout();
}
}
菜单项将我指向/index.php/donor/index/index/key/e98a...
,该页面显示404页.当我尝试直接转到/donor
,/index.php/donor
,/index.php/donor/index
等时,仍然出现404错误.
The menu item points me to /index.php/donor/index/index/key/e98a...
which shows a 404 page. When I try to go directly to /donor
, /index.php/donor
, /index.php/donor/index
, etc I still get 404 errors.
如果我从配置中删除了<helpers>
,Magento会抱怨找不到它.如果我删除了<adminhtml>
部分,即使我仍然有我的<admin><routers>
部分,它也会停止抱怨(不知道路由工具是否需要帮助程序,或者这是否有用).
If I remove the <helpers>
from the config, Magento complains that it can't find it. If I remove the <adminhtml>
section, it stops complaining, even though I still have my <admin><routers>
section in there (don't know if the routing stuff needs a helper or if this is even relevant).
我也尝试在<adminhtml>
下添加此块,但是当我尝试编辑角色权限时,出现了以下错误的白页:Fatal error: Class 'Mage_Mynamespace_Donor_Helper_Data' not found in /home/mysite/public_html/magento_dev_1_10/app/Mage.php on line 520
I've also tried adding this block under <adminhtml>
, but it when I try editing role permissions I get a white page with this error: Fatal error: Class 'Mage_Mynamespace_Donor_Helper_Data' not found in /home/mysite/public_html/magento_dev_1_10/app/Mage.php on line 520
<acl>
<resources>
<admin>
<children>
<donor translate="title" module="Mynamespace_Donor">
<title>Donors</title>
<sort_order>60</sort_order>
<children>
<manage_donors>
<title>Manage Donors</title>
</manage_donors>
</children>
</donor>
</children>
</admin>
</resources>
</acl>
问题:我在这里做错了什么?为什么我不能访问此控制器?
Question: What am I doing wrong here? Why can I not access this controller?
最后,在Alan的示例代码中,URL以模块名称开头,但是我希望我以/admin/donor
而不是/donor
开头.我需要对此进行哪些更改?
And lastly, in Alan's sample code, the URL began with the module name, but I would like mine to start with /admin/donor
instead of /donor
. What changes do I need to make for this?
编辑1 最终目标是在管理区域中具有一个新选项卡,用于管理系统中的捐助者和相关数据.当您单击某个菜单项时,我想显示一个网格并具有子选项卡和类似的内容.我不是要覆盖adminhtml控制器-尽管我根据 Alan的建议进行了扩展 a>:
Edit 1 The ultimate goal is to have a new tab in the admin area for managing Donors and related data in the system. When you click on some menu item, I'd like to show a grid and have sub-tabs and stuff like that. I'm not looking to override the adminhtml controller - although I am extending it per Alan's suggestion:
与标准的唯一区别 这里的控制者是我们 延伸 Mage_Adminhtml_Controller_Action 代替 Mage_Core_Controller_Varien_Action. Mage_Adminhtml_Controller_Action 包含用于验证的重要代码 管理员会话,以及几个 在管理员中有用的方法 控制台上下文.
The only difference from a standard controller here is that we’re extending Mage_Adminhtml_Controller_Action instead of Mage_Core_Controller_Varien_Action. Mage_Adminhtml_Controller_Action contains important code for validating the admin session, as well as several methods that are useful in an Admin Console context.
因此在这张图片中,单击该子菜单的第一个子菜单项应调用我的控制器的Index动作,并显示一个网格或用于管理捐助者的内容.
So in this picture, clicking that first sub-menu item should call the Index action of my controller and show a grid or something to manage the Donors.
推荐答案
尝试替换:
<frontname>donor</frontname>
与:
<frontName>donor</frontName>
这将解决您的404错误.
That will fix your 404 error.
这篇关于Magento管理员路由不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!