0

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/Rohan/CreateAdminController/etc

<config>
    <modules>
        <Rohan_CreateAdminController>
            <version>1.0.0</version>
        </Rohan_CreateAdminController>
    </modules>
<global>
    <helpers>
        <rohan_createadmincontroller>
            <!-- Helper definition needed by Magento -->
            <class>Mage_Core_Helper</class>
        </rohan_createadmincontroller>
    </helpers>
</global>

<adminhtml>
    <layout>
        <updates>
            <Rohan_CreateAdminController>
                <file>rohan_createadmincontroller.xml</file>
            </Rohan_CreateAdminController>                
        </updates>
    </layout>
</adminhtml>        

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

This is my adminhtml.xml file

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

<?xml version="1.0" encoding="UTF-8"?>
<config>
    <menu>
    <mycustomtab module="rohan_createadmincontroller" translate="title">
    <title>My Custom Tab</title>
    <sort_order>100</sort_order>
        <children>
        <index module="rohan_createadmincontroller" translate="title">
          <title>Index Action</title>
          <sort_order>1</sort_order>
          <action>adminhtml/custom</action>
        </index>

        <list module="rohan_createadmincontroller" translate="title">
          <title>List Action</title>
          <sort_order>2</sort_order>
          <action>adminhtml/custom/list</action>
        </list>

        <third module="rohan_createadmincontroller" translate="title">
          <title>Third Action</title>
          <sort_order>3</sort_order>
          <action>adminhtml/custom/third</action>
        </third>

        </children>
    </mycustomtab>
</menu>
<acl>
    <resources>
        <admin>
            <children>
                <custom translate="title" module="rohan_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>

` This is my CustomController.php file

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

<?php

class Rohan_CreateAdminController_Adminhtml_CustomController extends Mage_Adminhtml_Controller_Action
{
  public function indexAction()
  {
    $this->loadLayout()
        ->_setActiveMenu('mycustomtab')
        ->_title($this->__('Index Action'));
    // my stuf

    echo "index";

    $this->renderLayout();

 }

public function listAction()
{
    $this->loadLayout()
        ->_setActiveMenu('mycustomtab')
        ->_title($this->__('List Action'));

    // my stuff
    echo "list"; 
    $this->renderLayout();
}

public function thirdAction()
{
    $this->loadLayout()
        ->_setActiveMenu('mycustomtab')
        ->_title($this->__('Third Action'));

    // my stuff
    echo "third"; 
       $this->renderLayout();
   }
}

This is the result enter image description here

I want to display something in the main area. I know i need to create layout and template files for this but I can't understand how to do that.

0

To create a layout file, add a rohan_createadmincontroller.xml file at app/design/adminhtml/default/default/rohan_createadmincontroller.xml.

This file should look something similar to this:

<?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>
    <adminhtml_custom_third>
        <reference name="content">
            <block type="core/template" name="custom_third" template="custom/third.phtml" />
        </reference>
    </adminhtml_custom_third>
</layout>

Then you will need to create templates at app/design/frontend/your_vendor/your_theme/template/custom/index.phtml, app/design/frontend/your_vendor/your_theme/template/custom/list.phtml, and app/design/frontend/your_vendor/your_theme/template/custom/third.phtml. In those template files put whatever you want.

  • Thank you! This worked. Although added the templates at app/design/adminhtml/default/default/template/custom instead of app/design/frontend – Rohan Bhatia Mar 19 '17 at 22:02

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.