Magento – Custom Admin controller not displaying in magento

magento-1.6php-5.4

I have created easylife admincontroller and it configure the config.xml, and I give the Url-> protocal://Ipaddress/ics/admin/admintest but it's not displaying.

can any one tell me where I went wrong?

my code is:

Ics->EasyLife->controllers->Adminhtml->IndexController.php

<?php

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

Ics->EasyLife->Block->Adminhtml->Template.php

<?php
class Ics_EasyLife_Block_Adminhtml_Template extends Mage_Adminhtml_Block_Widget_Form
{
    public function MyMethod()
    {
        echo "Admin Html Page Method";
    }
}

Ics->EasyLife->etc->config.xml

<admin>
        <routers>
            <icscontroller>
                <use>admin</use>
                <args>
                    <module>Ics_EasyLife</module>
                    <frontName>admintest</frontName>
                </args>
            </icscontroller>
        </routers>
    </admin>

thanks in advance.

Best Answer

I don't like that method of providing your own frontName, I prefer to overload the existing admin router because it's neat and quick. Start by changing this in your config.xml:

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <ics_easylife before="Mage_Adminhtml">Ics_EasyLife_Adminhtml</ics_easylife>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

This will make magento check for controller classes that start with Ics_EasyLife_Adminhtml before checking it's own Mage_Adminhtml. Rename your controller to Ics_EasyLife_Adminhtml_EasylifeController and rename it's corresponding file to EasylifeController.php.

Now an URL of adminhtml/easylife will expand to http://ipaddress/ics/admin/easylife/index and call your indexAction method. When making a menu entry use that URL of adminhtml/easylife. Even if you don't have any layout or blocks in place yet at least a page will show. When writing a layout use the layout handle <adminhtml_easylife_index>.

Related Topic