1

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

  • Please enable developer mode of your magento so that you can see the exact error. – Gulshan Apr 4 '17 at 1:31
1

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.

  • I have also defined custom template path:app\design\adminhtml\default\default\template\custom 1. index.phtml 2. list.phtml But its not working – Umer Apr 4 '17 at 19:23
  • What do you want to end up with? Question is if you need a custom template. Magento has the option to add a grid page without setting a template. For that, you might want to check out this post by Inchoo: inchoo.net/magento/how-to-create-a-custom-grid-from-scratch – Arjen Miedema Apr 5 '17 at 5:09
  • Thankyou :) it helps alot – Umer Apr 5 '17 at 20:26
-2

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

  • 1
    Glad I could help. You could have just marked my answer as the solution instead of copying it partially as a new answer. – Arjen Miedema Apr 5 '17 at 5:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.