2

Im try to make a Magento Admin area module but have got stuck with a link issue.

So far I have my required option in the menu bar but my problem comes when I click the link, I get a 404 error, I expected a grid. I am following a tutorial from excellencemagentoblog.

I understand that the action node within the children node of the tree is the link and I have followed my file path to create what I expected would be the correct link, but that failes and I cannot work out why?

My code is

excellence/employee/adminHtml.xml

<config>
<menu><!--action node, URL of admin controller-->
    <employee module="employee">
        <title>Employee</title>
        <sort_order>90</sort_order>
        <children>
            <items module="employee"><!--adds menu item-->
                <title>Manage Employees</title>
                <sort_order>0</sort_order>
                <action>employee/adminhtml_employee</action><!--Link-->
            </items>
        </children>
    </employee>
</menu>
<acl>
    <resources>
        <all>
            <title>Allow Everthing</title>
        </all>
        <admin>
            <children>
                <excellence_employee>
                    <title>Employee Module</title>
                    <sort_order>10</sort_order>
                </excellence_employee>
            </children>
        </admin>
    </resources>
</acl>
<layout>
    <updates>
        <employee>
            <file>employee.xml</file>
        </employee>
    </updates>
</layout>
</config>

Excellence/Employee/controllers/AdminHtml/EmployeeController.php

class Excellence_Employee_Adminhtml_EmployeeController
    extends Mage_Adminhtml_Controller_Action
{
    public function indexAction()
    {
        $this->loadLayout();
        $this->renderLayout();
    }
}

I have tried logging out and back in again, but I still get the 404. What have i do wrong?

When I click the link the address is

http://magentodevtest.local/index.php/employee/adminhtml_employee/index/key/45435404fsd453453

I have added an image of my file structure, looking at the address bar, my understanding of how files are accessed says it should work (i obviously misunderstand something)Img of the file structure

===EDIT===

I have cache disabled

My config.xml is as follows

<config>
<modules>
    <Excellence_Employee>
        <version>0.1.0</version>
    </Excellence_Employee>
</modules>
<global>
    <blocks>
        <employee>
            <class>Excellence_Employee_Block</class>
        </employee>
    </blocks>
    <models>
        <employee>
            <class>Excellence_Employee_Model</class>
        </employee>
    </models>
    <helpers>
        <employee>
            <class>Excellence_Employee_Helper</class>
        </employee>
    </helpers>
</global>
</config>
2
  • First try clearing the cache. If nothing happens post the contents of config.xml in the question. Also...small tip: rename adminHtml.xml to adminhtml.xml. You will have problems if you don't on other OS.
    – Marius
    Commented Aug 29, 2013 at 10:57
  • @Marius, Please see my edit. I have changed adminHtml.xml as you suggested
    – tony09uk
    Commented Aug 29, 2013 at 11:10

1 Answer 1

5

As I suspected you are missing the routers in your config.xml. Add this node under the <global> node:

<admin>
    <routers>
       <employee>
           <use>admin</use>
           <args>
               <module>Excellence_Employee</module>
               <frontName>employee</frontName>
           </args>
       </employee>
    </routers>
</admin>

Or better yet. a more elegant solution is to have your module have the path start with admin like all the admin modules. For this, instead of the code above add this:

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <Excellence_Employee before="Mage_Adminhtml">Excellence_Employee_Adminhtml</Excellence_Employee>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

After adding this your module admin url should look like this admin/employee/index.
And you should change the <action> in your menu to

<action>adminhtml/employee</action>

I recommend the second option. It's nicer and has some advantages if you want to use for example Varnish in front of your server. It's easier to configure.

[EDIT]
The first solution does not work anymore, in versions 1.9.2+ and presents a security risk for versions previous to that.

4
  • Thankyou for your help. I have added the admin node to the global node and changed the action node. My url like like what you suggested, but I am still getting a 404, do you have any other suggestions?
    – tony09uk
    Commented Aug 29, 2013 at 11:37
  • maybe clear the cache. Or you can check this for suggestions magento.stackexchange.com/questions/428/…
    – Marius
    Commented Aug 29, 2013 at 11:49
  • Thnks for that link. It hasnt covered what I was looking for. I know its a simple error somewhere in my config. i will keep looking
    – tony09uk
    Commented Aug 29, 2013 at 12:24
  • Thanks to Marius I was able to work through my remaining problems and work out that I had deleted the </global> node when I added his solution
    – tony09uk
    Commented Aug 29, 2013 at 14:11

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.