1

All I'm trying to do is follow http://alanstorm.com/magento_admin_controllers basically to create a page in the admin section but it doesn't find it, 404.

IndexController.php:

<?php

class VMRReports_AdminHelloWorld_IndexController extends Mage_Adminhtml_Controller_Action {
    public function indexAction() {
        echo 'Hello Index!';
        $this->loadLayout();
        $this->renderLayout();
        }
}

config.xml:

<config>
        <modules>
                <VMRReports_AdminHelloWorld>
                        <version>1.0</version>
                </VMRReports_AdminHelloWorld>
        </modules>
        <admin>
                <routers>
                        <VMRReports_AdminHelloWorld>
                                <use>admin</admin>
                                <args>
                                <modules>VMRReports_AdminHelloWorld</modules>
                                <frontName>adminhelloworld</frontName>
                                </args>
                        </VMRReports_AdminHelloWorld>
                </routers>
        </admin>
        <adminhtml>
        <!-- The <layout> updates allow us to define our block layouts in a seperate file so are aren't messin' with the magento layout files.  -->
        <layout>
            <updates>
                <hello>
                    <file>hello.xml</file>
                </hello>
            </updates>
        </layout>
        <!-- The <acl> section is for access control. Here we define the pieces where access can be controlled within a role. -->
        <acl>
            <resources>
                <admin>
                    <children>
                        <hello module="VMRReports_HelloWorld">
                            <title>Hello Menu Item</title>
                            <children>
                                <example translate="title" module="hello">
                                    <title>Example Menu Item</title>
                                </example>
                            </children>
                        </hello>
                    </children>
                </admin>
            </resources>
        </acl>
    </adminhtml>
    <global>
        <helpers>
            <helloworld>
                <class>VMRReports_HelloWorld_Helper</class>
            </helloworld>
        </helpers>
        <resources>
            <helloworld_setup>
                <setup>
                    <module>VMRReports_HelloWorld</module>
                </setup>
            </helloworld_setup>
        </resources>
    </global>
</config>

What is wrong?

3
  • Have you tried logging out and back in again or visiting the same resource in incognito mode? If that works, let me know and I'll post as an answer.
    – philwinkle
    Commented May 2, 2013 at 17:20
  • I get 404 when I try to go to: my site.com/admin/helloworld
    – user2045
    Commented May 2, 2013 at 17:20
  • I have tried logging out and in again. What is incognito mode?
    – user2045
    Commented May 2, 2013 at 17:20

4 Answers 4

9

As mentioned by others, it's preferable to use the <modules/> node in the <routers/> node — this article was the first one I saw that outlined the feature in full. This technique will allow you to have your URLs at the /admin frontname, which certain AJAX form features rely on.

The technique described in my article describes setting up a custom front name for the admin, so for your configuration that would create URLS like this

http://store.example.com/index.php/adminhelloworld
http://store.example.com/index.php/adminhelloworld/index/index

The reason your module is failing are multiple. First, your config.xml isn't valid XML. The following triggers a non-well formed error.

<use>admin</admin>

Try running Magento in developer mode when you're working on development tasks. Doing this will cause the system to fail on non valid XML files (instead of silently ignoring them)

Second, you have a typo. This

<modules>VMRReports_AdminHelloWorld</modules>

should be singular

<module>VMRReports_AdminHelloWorld</module>

Also, remember that you can't, by default, browse directly to admin URLs. You need to use an admin menu or other generated URL that uses the nonce. You can skip this check by using the _publicActions property, but this opens your backend code to cross site request forgery attacks.

class VMRReports_AdminHelloWorld_IndexController extends Mage_Adminhtml_Controller_Action {
    protected $_publicActions = array('index');
    public function indexAction() {
        echo 'Hello Index!';
        $this->loadLayout();
        $this->renderLayout();
        }
}
2
4

Try this,

  1. Create app/code/local/VMRReports/AdminHelloWorld/etc/config.xml
<?xml version="1.0"?>
      <config>
        <modules>
            <VMRReports_AdminHelloWorld>
                <version>0.1.0</version>
            </VMRReports_AdminHelloWorld>
        </modules>
        <global>
            <models>
                <adminhelloworld>
                    <class>VMRReports_AdminHelloWorld_Model</class>
                </adminhelloworld>
            </models>
            <blocks>
                <adminhelloworld>
                    <class>VMRReports_AdminHelloWorld_Block</class>
                </adminhelloworld>
            </blocks>
            <helpers>
                <adminhelloworld>
                    <class>VMRReports_AdminHelloWorld_Helper</class>
                </adminhelloworld>
            </helpers>
        </global>
        <admin>
            <routers>
                <adminhelloworld>
                    <use>admin</use>
                    <args>
                        <module>VMRReports_AdminHelloWorld</module>
                        <frontName>adminhelloworld</frontName>
                    </args>
                </adminhelloworld>
            </routers>
        </admin>
    </config>
  1. Create app/code/local/VMRReports/AdminHelloWorld/etc/adminhtml.xml
<?xml version="1.0"?>
<config>
    <menu>
        <adminhelloworld>
            <title>Example Menu Item</title>
            <sort_order>32</sort_order>
            <action>adminhelloworld/adminhtml_index/index</action>
        </adminhelloworld>
    </menu>
    <layout>
        <updates>
            <adminhelloworld>
                <file>hello.xml</file>
            </adminhelloworld>
        </updates>
    </layout>
</config>
  1. Create app/code/local/VMRReports/AdminHelloWorld/controllers/Adminhtml/IndexController.php
<?php
class VMRReports_AdminHelloWorld_Adminhtml_IndexController extends Mage_Adminhtml_Controller_Action
{
    public function indexAction() 
    {
        $this->loadLayout();
        $block = $this->getLayout()
                        ->createBlock('core/text', 'example-block')
                        ->setText('<h1>Hello World</h1>');

        $this->_addContent($block);
        $this->renderLayout();
    }
}
  1. Create helper class. app/code/local/VMRReports/AdminHelloWorld/Helper/Data.php
<?php
class VMRReports_AdminHelloWorld_Helper_Data extends Mage_Adminhtml_Helper_Data
{

}
  1. Now create Module Activation file app/etc/modules/VMRReports_AdminHelloWorld.xml
<?xml version="1.0"?>
    <config>
        <modules>
            <VMRReports_AdminHelloWorld>
                <active>true</active>
                <codePool>local</codePool>
            </VMRReports_AdminHelloWorld>
        </modules>
    </config>
  1. Then Clear the cache and logout from admin and login again. You'll see the screen below.

enter image description here

Hope this helps.

  1. Finally click on the menu Example Menu Item and you'll see the screen below.

enter image description here

NOTE: You can put ACL info in adminhtml.xml

4

It is better to use the following router definition:

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

You then create the file: controllers/HelloworldController.php with the following:

 class VMRReports_AdminHelloWorld_HelloworldController extends Mage_Adminhtml_Controller_Action {

        public function indexAction() {
        // Your code here
        }

You can then access the url via: http://[hostname]/index.php/admin/Helloworld/ (where admin is the admin code you are using to access the backend)

Hope this solves your problem.

5
  • For the code you are using now you should access the the following url:my site.com/index.php/adminhelloworld/ Commented May 2, 2013 at 17:28
  • I need http://[hostname]/index.php/admin/Helloworld/
    – user2045
    Commented May 2, 2013 at 17:34
  • Also, that didnt seem to work for me. Still 404
    – user2045
    Commented May 2, 2013 at 17:34
  • I'm editing app/code/local/VMRReports/AdminHelloWorld/controllers/... and app/code/local/VMRReports/AdminHelloWorld/etc/config.xml right?
    – user2045
    Commented May 2, 2013 at 17:35
  • Yes that are the files to edit. Commented May 2, 2013 at 17:55
-1

If you scroll to the bottom of this link you will find an explanation and an example of what you are trying to do

http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/custom_module_with_custom_database_table

Hope this helps!

0

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.