1

I create a menu Employee on admin panel. This menu has a sub menu Manage Employees. When I click on Manage Employees I get an 404 error. The given below are my codes:

The given below is a part of my controller Location: /var/www/html/magento/app/code/local/Test/User/etc

<adminhtml>
  <menu>
   <user module="adminhtml">
    <title>Employee</title>
    <sort_order>71</sort_order>              
    <children>
     <items module="user">
      <title>Manage Employees</title>
      <sort_order>0</sort_order>
      <action>adminhtml/adminhtml_employee/</action>
     </items>
    </children>
   </user>
  </menu>
  <acl>
   <resources>
    <all>
     <title>Allow Everything</title>
    </all>
    <admin>
     <children>
      <Test_User>
       <title>Employee Module</title>
       <sort_order>10</sort_order>
      </Test_User>
     </children>
    </admin>
   </resources>
  </acl>
  <layout>
   <updates>
    <user>
     <file>user.xml</file>
    </user>
   </updates>
  </layout>
 </adminhtml> 

This is my controller Location: /var/www/html/magento/app/code/local/Test/User/controllers/Adminhtml

<?php
 class Test_User_Adminhtml_EmployeeController extends Mage_Adminhtml_Controller_action
  {
   public function indexAction()
    {
     $this->loadLayout();
     $this->renderLayout();
    }
  }
?>

This are the block files Location: /var/www/html/magento/app/code/local/Test/User/Block/Adminhtml

<?php
 class Test_User_Block_Adminhtml_Employee extends Mage_Adminhtml_Block_Widget_Grid_Container
  {
   public function __construct()
   {
    $this->_controller = 'adminhtml_employee';
    $this->_blockGroup = 'employee';
    $this->_headerText = Mage::helper('employee')->__('Employee Manager');
    $this->_addButtonLabel = Mage::helper('employee')->__('Add Employee');
    parent::__construct();
   }
  }
?>

Location: /var/www/html/magento/app/code/local/Test/User/Block/Adminhtml/Employee

<?php 
 class Test_User_Block_Adminhtml_Employee_Grid extends Mage_Adminhtml_Block_Widget_Grid
  {
    public function __construct()
    {
        parent::__construct();
        $this->setId('employeeGrid');
        $this->setDefaultSort('id');
        $this->setDefaultDir('ASC');
        $this->setSaveParametersInSession(true);
    }

    protected function _prepareCollection()
    {
        $collection = Mage::getModel('user/employee')->getCollection();
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

    protected function _prepareColumns()
    {
        $this->addColumn('id', array(
          'header'    => Mage::helper('employee')->__('ID'),
          'align'     =>'right',
          'width'     => '10px',
          'index'     => 'id',
        ));

        $this->addColumn('name', array(
          'header'    => Mage::helper('employee')->__('Name'),
          'align'     =>'left',
          'index'     => 'name',
          'width'     => '50px',
        ));


        $this->addColumn('content', array(
            'header'    => Mage::helper('employee')->__('Description'),
            'width'     => '150px',
            'index'     => 'content',
        ));
        return parent::_prepareColumns();
    }
  }
?>

and this is my xml file user.xml present inside my module:

<?xml version="1.0"?>
<layout version="0.1.0">
<employee_adminhtml_employee_index>
        <reference name="content">
            <block type="employee/adminhtml_employee" name="employee" />
        </reference>
    </employee_adminhtml_employee_index>
</layout>

1 Answer 1

1

add this in you config.xml

   <admin>
        <routers>
             <adminhtml>
                <args>
                    <modules>
                        <Test_User before="Mage_Adminhtml">Test_User_Adminhtml</Test_User>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>

then in you layout xml mean user.xml

<?xml version="1.0"?>
<layout version="0.1.0">
<adminhtml_employee_index>
        <reference name="content">
            <block type="employee/adminhtml_employee" name="employee" />
        </reference>
    </adminhtml_employee_index>
</layout>

Now the action will be

<adminhtml>
  <menu>
   <user module="adminhtml">
    <title>Employee</title>
    <sort_order>71</sort_order>              
    <children>
     <items module="user">
      <title>Manage Employees</title>
      <sort_order>0</sort_order>
      <action>adminhtml/employee/</action>
     </items>
    </children>
   </user>
  </menu>
  <acl>
   <resources>
    <all>
     <title>Allow Everything</title>
    </all>
    <admin>
     <children>
      <Test_User>
       <title>Employee Module</title>
       <sort_order>10</sort_order>
      </Test_User>
     </children>
    </admin>
   </resources>
  </acl>
  <layout>
   <updates>
    <user>
     <file>user.xml</file>
    </user>
   </updates>
  </layout>
 </adminhtml> 
3
  • Thank you very much. Now its not giving error. I want to ask one more thing. In the above code inside block folder I added this code protected function _prepareCollection() { $collection = Mage::getModel('user/employee')->getCollection(); $this->setCollection($collection); return parent::_prepareCollection(); }
    – Birju
    Commented Mar 21, 2017 at 12:04
  • $collection = Mage::getModel('user/employee')->getCollection(); Should I have to create a model employee or is it a kind of pre-defined.
    – Birju
    Commented Mar 21, 2017 at 12:06
  • @Birju you have to create the model nothing is predefined . follow this alanstorm.com/magento_models_orm Commented Mar 21, 2017 at 12:07

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.