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.
(Note: I have included all relevant code here. The actual question is at the very bottom.)
The module is called Mynamespace_Donor and lives in app/code/local/Mynamespace/Donor/.
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>
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();
}
}
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.
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).
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?
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?
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:
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.
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.
