Question

I've created a module which creates a custom tab in the admin panel but I've not been able to display the required data.`

This is my config.xml file

Path: app/code/community/JR/CreateAdminController/etc

<?xml version="1.0"?>
<config>
<modules>
    <JR_CreateAdminController>
        <version>1.0.0</version>
    </JR_CreateAdminController>
</modules>
<global>
    <helpers>
        <jr_createadmincontroller>
            <!-- Helper definition needed by Magento -->
            <class>Mage_Core_Helper</class>
        </jr_createadmincontroller>
    </helpers>
</global>

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <foo_bar before="Mage_Adminhtml">JR_CreateAdminController_Adminhtml</foo_bar>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>
</config>

This is my adminhtml.xml file

path: app/code/community/JR/CreateAdminController/etc

<?xml version="1.0" encoding="UTF-8"?>
<config>
<menu>
    <mycustomtab module="jr_createadmincontroller" translate="title">
        <title>My Custom Tab</title>
        <sort_order>100</sort_order>
        <children>
            <index module="jr_createadmincontroller" translate="title">
                <title>Index Action</title>
                <sort_order>1</sort_order>
                <action>adminhtml/custom</action>
            </index>
            <list module="jr_createadmincontroller" translate="title">
                <title>List Action</title>
                <sort_order>2</sort_order>
                <action>adminhtml/custom/list</action>
            </list>
        </children>
    </mycustomtab>
</menu>
<acl>
    <resources>
        <admin>
            <children>
                <custom translate="title" module="jr_createadmincontroller">
                    <title>My Controller</title>
                    <sort_order>-100</sort_order>
                    <children>
                        <index translate="title">
                            <title>Index Action</title>
                            <sort_order>1</sort_order>
                        </index>
                        <list translate="title">
                            <title>List Action</title>
                            <sort_order>2</sort_order>
                        </list>
                    </children>
                </custom>
            </children>
        </admin>
    </resources>
</acl>
</config>

This is my CustomController.php file

Path: app/code/community/JR/CreateAdminController/controllers/Adminhtml

<?php
class JR_CreateAdminController_Adminhtml_CustomController extends       Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
    $this->loadLayout()
        ->_setActiveMenu('mycustomtab')
        ->_title($this->__('Index Action'));

    // my stuff

    $this->renderLayout();
}

public function listAction()
{

    $this->loadLayout()
        ->_setActiveMenu('mycustomtab')
        ->_title($this->__('List Action'));

        //var_dump(Mage::getSingleton('core/layout')->getUpdate()->getHandles());
        //die();
    // my stuff
        echo "string";

    $this->renderLayout();
}
}

This is my jr_createadmincontroller.xml file

path:app/design/adminhtml/default/default/jr_createadmincontroller.xml

<?xml version="1.0"?>
<layout>
<adminhtml_custom_index>
    <reference name="content">
        <block type="core/template" name="custom_index" template="custom/index.phtml" />
    </reference>
</adminhtml_custom_index>
<adminhtml_custom_list>
    <reference name="content">
        <block type="core/template" name="custom_list" template="custom/list.phtml" />
    </reference>
</adminhtml_custom_list>

</layout>

The Path of Custom folder is app/design/adminhtml/default/default/Template/Custom

There is index.phtml and list.phtml

But nothing showing in admin panel screen enter image description here

Was it helpful?

Solution

The first thing that comes to mind is: where are your block classes? To show stuff you need both a controller and a block. And you need to define the blocks for the layout handle as well. The code you're using now is rendered correctly, but you didn't define any content.

I see you used the code from Bubblecode, which also has comments that the code isn't working.

An extension that shows stuff in any page, requires at least a Controller (which you already have), a Block class and a helper (for translations, etc).

To define your blocks you need to add this in your config.xml file between the <global></global> tags:

<blocks>
    <jr_createadmincontroller>
        <class>JR_CreateAdminController_Block</class>
    </jr_createadmincontroller>
</blocks>

After that, you will need to create a custom layout file, which will be used to load the blocks into your page. To do this, you need the following things:

Define adminhtml layout file
In your config.xml create a section <adminhtml> after the closing tag for <global>:

<adminhtml>
    <layout>
        <updates>
            <jr_createadmincontroller>
                <file>jr_createadmincontroller.xml</file>
            </jr_createadmincontroller>
        </updates>
    </layout>
</adminhtml>

Now you need to create this layout XML file, which should be located at app/design/adminhtml/default/default/layout/jr_customcontroller.xml. The code you need in this file will look something like this:

<?xml version="1.0"?>
<layout>
    <adminhtml_createadmincontroller_custom_index>
        <reference name="content">
            <block type="jr_createadmincontroller/adminhtml_custom" name="name.of.your.block" />
        </reference>
    </adminhtml_createadmincontroller_custom_index>
</layout>

After this, you might have to create templates as well, or you should use the default grid functionality, based on the ones Magento uses for the products, CMS pages, etc.

Of course, the above code doesn't work out of the box, but I hope it will give you a better understanding of what you need to get content into your own adminhtml controller.

OTHER TIPS

Error resolved by putting the layout code in config.xml file below ending tag of Global

<adminhtml>
    <layout>
        <updates>
            <jr_createadmincontroller>
                <file>jr_createadmincontroller.xml</file>
            </jr_createadmincontroller>
        </updates>
    </layout>
</adminhtml>

and by putting the jr_createadmincontroller.xml file into

Path: app/design/adminhtml/default/default/layout/jr_createadmincontroller.xml

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top