1

Ok, I am once again making a simple module to place something in the admin section. When I do the following:

config.xml:

<?xml version="1.0"?>
<config>
    <module>
        <VMRReports_AdminHelloWorld>
            <version>1.0</version>
        </VMRReports_AdminHelloWorld>
    </module>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <helloworld before="Mage_Adminhtml">VMRReports_AdminHelloWorld</helloworld>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

controller/IndexController.php:

<?php 

class VMRReports_AdminHelloWorld_IndexController extends Mage_Adminhtml_Controller_Action {        
    protected $_publicActions = array('index');
    public function IndexAction() {
        echo 'Hello Index!';
    }
}

it replaces mysite.com/admin/index. What would I change to get it to do stuff in mysite.com/admin/helloworld? In mysite.com/admin/index, is index the controller?

2 Answers 2

3

What's going awry here is the name of your controller file doesn't match the route. The config XML tells Magento to look at your controllers before any starting with the prefix of Mage_Adminhtml. The rest of the controller name (and file path) is defined by the URL. So in your case, and with your existing config, you need to name the controller file HelloworldController.php so that it is loaded up on that route name.

The node name helloworld in your markup means nothing in terms of what route is attached to the controller. It is merely a module identifier in the XML, same as what you'd use when declaring model, block, helper class prefixes.

A couple other notes though:

  1. Since you are creating a new controller and are not rewriting an existing action, you should use the after property instead of before. This is so that default controllers take precedence and Magento doesn't have to look in your module for valid controllers before routing every request.

  2. I would recommend putting all of your admin related controllers in a folder identifying them as such, i.e. controllers/Adminhtml/ within your module. Then add _Adminhtml to the end of your class prefix defined in the XML

An implementation of the two suggestions I mention here would look like this:

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <helloworld after="Mage_Adminhtml">VMRReports_AdminHelloWorld_Adminhtml</helloworld>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

And not to leave the class file out:

class VMRReports_AdminHelloWorld_Adminhtml_HelloworldController extends Mage_Adminhtml_Controller_Action {        
    public function IndexAction() {
        echo 'Hello Index!';
    }
}
4
  • If I wanna do, mysite.com/admin/helloworld, is 'helloworld' the controller?
    – user2045
    Commented May 3, 2013 at 20:08
  • Yes, that is correct. And if you were to have say 'admin/hello_world' then your controller would be Hello/WorldController.php
    – davidalger
    Commented May 3, 2013 at 21:52
  • 1
    after breaks 404 routing in the admin unfortunately (or it did) - Vinai told me this, iirc
    – benmarks
    Commented May 4, 2013 at 13:00
  • @Benmarks Hmm...interesting. Never noticed that, and if it did, I sure hope it's fixed by now...otherwise it calls for a bug report on core. :)
    – davidalger
    Commented May 4, 2013 at 15:11
0

Try it in controllers/Adminhtml/IndexController.php and update your class accordingly.

1
  • how would that make /admin/helloworld do anything?
    – user2045
    Commented May 3, 2013 at 17:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.