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?

philwinkle
  • 35,751
  • 5
  • 91
  • 145
user2045
  • 831
  • 3
  • 16
  • 29

4 Answers4

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();
        }
}
Alana Storm
  • 44,345
  • 35
  • 168
  • 353
  • So you cant have something of the form, http://store.example.com/index.php/admin/helloworld with that slash in between admin and module name? – user2045 May 02 '13 at 20:47
  • @user2045 Not using the technique described in that article. If you want urls in the form of /index.php/admin/helloworld, you need to use the method described in the linked article. http://web-magician.blogspot.com/2009/04/secret-feature-of-magento-13-sharing.html – Alana Storm May 02 '13 at 21:35
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.

Raphael at Digital Pianism
  • 70,385
  • 34
  • 188
  • 352
Vladimir Kerkhoff
  • 8,223
  • 1
  • 35
  • 41
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

Sukeshini
  • 9,945
  • 18
  • 71
  • 126
-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!

Jeffrey L. Roberts
  • 1,317
  • 2
  • 21
  • 31