Magento – Understanding admin links

adminhtml

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>

Best Answer

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.

Related Topic