12
votes

I am new in Magento. I am trying to develop a custom module for Magento Admin panel. My codes are as follows

Location : app/etc/modules

Digitab_Brandlogo.xml

<?xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <Digitab_Brandlogo>
            <active>true</active>
            <codePool>local</codePool>
        </Digitab_Brandlogo>
    </modules>
</config>

Location : app/code/local/Digitab/Brandlogo/Block/Adminhtml

logo.php

<?php
    class Digitab_Brandlogo_Block_Adminhtml_slider extends Mage_Adminhtml_Block_Widget_Grid_Container
    {
        public function __construct()
        {
                $this->_controller = 'adminhtml_brandlogo';
                $this->_blockGroup = 'brandlogo';
                $this->_headerText = Mage::helper('brandlogo')->__('Brand Logo Manager');
            $this->_addButtonLabel = Mage::helper('brandlogo')->__('Add Brand');
                parent::__construct();
        }
    }

Location: app/code/local/Digitab/Brandlogo/controllers/Adminhtml

IndexController.php

<?php

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

location: app/code/local/Digitab/Brandlogo/etc

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <digitab_brandlogo>
            <version>1.0.0</version>
        </digitab_brandlogo>
    </modules>
    <global>
        <models />
        <blocks />
        <resources />
        <extraconfig />
        <helpers>
            <digitab_brandlogo>
                <class>Digitab_Brandlogo_Helper</class>
            </digitab_brandlogo>
        </helpers>
    </global>
    <admin>
        <routers>
            <digitab_brandlogo>
                <use>admin</use>
                <args>
                    <module>Digitab_brandlogo</module>
                    <frontName>brandlogo</frontName>
                </args>
            </digitab_brandlogo>
        </routers>
    </admin>
    <adminhtml>
        <layout>
        <updates>
            <brandlogo>
                <file>brandlogo.xml</file>
            </brandlogo>
        </updates>
    </layout>
    </adminhtml>
</config>

location: app/code/local/Digitab/Brandlogo/etc

adminhtml.xml

<?xml version="1.0"?>
<config>
    <menu>
        <digitab translate="title" module="digitab_brandlogo">
            <title>Digitab</title>
            <sort_order>110</sort_order>
            <children>
                <brandlogo>
                    <title>Brand Logo</title>
                    <sort_order>1</sort_order>
                    <action>brandlogo/adminhtml_brandlogo</action>
                </brandlogo>
            </children>
        </digitab>
    </menu>
</config>

location: app/code/local/Digitab/Brandlogo/Helper

Data.php

<?php
class Digitab_Brandlogo_Helper_Data extends Mage_Core_Helper_Abstract
{
}

location: app/design/adminhtml/default/default/layout

brandlogo.xml

<?xml version="1.0"?> 
<layout version="0.1.0">
    <brandlogo_adminhtml_brandlogo_index>
        <reference name="content">
            <block type="brandlogo/adminhtml_brandlogo" name="brandlogo" template="test.phtml"/>
        </reference>
    </brandlogo_adminhtml_brandlogo_index> 
</layout>

location:app/design/adminhtml/default/default/template

test.phtml

ABCD

I am getting output like below

enter image description here

How can I display the template ?? Can anyone help me in this regard?? Thanks





Update

I modified my files as below, but it is not working.

Location : app/etc/modules

Digitab_Brandlogo.xml

<?xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <Digitab_Brandlogo>
            <active>true</active>
            <codePool>local</codePool>
        </Digitab_Brandlogo>
    </modules>
</config>

Location : app/code/local/Digitab/Brandlogo/Block/Adminhtml

Brandlogo.php

<?php
    class Digitab_Brandlogo_Block_Adminhtml_Brandlogo extends Mage_Adminhtml_Block_Widget_Grid_Container
    {
        public function __construct()
        {
                $this->_controller = 'adminhtml_brandlogo';
                $this->_blockGroup = 'brandlogo';
                $this->_headerText = Mage::helper('brandlogo')->__('Brand Logo Manager');
            $this->_addButtonLabel = Mage::helper('brandlogo')->__('Add Brand');
                parent::__construct();
        }
    }

Location: app/code/local/Digitab/Brandlogo/controllers/Adminhtml

BrandlogoController

<?php

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

location: app/code/local/Digitab/Brandlogo/etc

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <digitab_brandlogo>
            <version>1.0.0</version>
        </digitab_brandlogo>
    </modules>
    <global>
        <models />
        <blocks>
            <brandlogo>
                <class>Digitab_Brandlogo_Block</class>
            </brandlogo>
        </blocks>
        <resources />
        <extraconfig />
        <helpers>
            <digitab_brandlogo>
                <class>Digitab_Brandlogo_Helper</class>
            </digitab_brandlogo>
        </helpers>
    </global>
    <admin>
        <routers>
            <digitab_brandlogo>
                <use>admin</use>
                <args>
                    <module>Digitab_brandlogo</module>
                    <frontName>brandlogo</frontName>
                </args>
            </digitab_brandlogo>
        </routers>
    </admin>
    <adminhtml>
    <layout>
        <updates>
            <brandlogo>
                <file>brandlogo.xml</file>
            </brandlogo>
        </updates>
    </layout>
    </adminhtml>
</config>

location: app/code/local/Digitab/Brandlogo/etc

adminhtml.xml

<?xml version="1.0"?>
<config>
    <menu>
        <digitab translate="title" module="digitab_brandlogo">
            <title>Digitab</title>
            <sort_order>110</sort_order>
            <children>
                <brandlogo>
                    <title>Brand Logo</title>
                    <sort_order>1</sort_order>
                    <action>brandlogo/adminhtml_brandlogo</action>
                </brandlogo>
            </children>
        </digitab>
    </menu>
</config>

location: app/code/local/Digitab/Brandlogo/Helper

Data.php

<?php
class Digitab_Brandlogo_Helper_Data extends Mage_Core_Helper_Abstract
{
}

location: app/design/adminhtml/default/default/layout

brandlogo.xml

<?xml version="1.0"?> 
<layout version="0.1.0">
    <brandlogo_adminhtml_brandlogo_index>
        <reference name="content">
            <block type="brandlogo/adminhtml_brandlogo" name="brandlogo" template="test.phtml"/>
        </reference>
    </brandlogo_adminhtml_brandlogo_index> 
</layout>

location:app/design/adminhtml/default/default/template

test.phtml

ABCD

But it is not working. Now I can see a blank white page in admin panel. Thanks

2

2 Answers

4
votes

Here is a complete answer:

Location: app/etc/modules

Digitab_Brandlogo.xml

Looks good.

Location: app/code/local/Digitab/Brandlogo/Block/Adminhtml

This folder needs to contain the below files & folders:

app/code/local/Digitab/Brandlogo/Block/Adminhtml/Brandlogo/Grid.php

<?php 
class Digitab_Brandlogo_Block_Adminhtml_Brandlogo_Grid extends Mage_Adminhtml_Block_Widget_Grid
{
    public function __construct()
    {
        parent::__construct();
        $this->setId('digitab_brandlogo_grid');
        $this->setDefaultSort('increment_id');
        $this->setDefaultDir('DESC');
        $this->setSaveParametersInSession(true);
        $this->setUseAjax(true);
    }

    public function getGridUrl()
    {
        return $this->getUrl('*/*/grid', array('_current'=>true));
    }
}

app/code/local/Digitab/Brandlogo/Block/Adminhtml/Brandlogo.php

<?php
class Digitab_Brandlogo_Block_Adminhtml_Brandlogo extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct()
    {
        $this->_blockGroup = 'digitab_brandlogo';
        $this->_controller = 'adminhtml_brandlogo';
        $this->_headerText = Mage::helper('digitab_brandlogo')->__('Brand Logo Manager');

        parent::__construct();
        $this->_addButtonLabel = Mage::helper('digitab_brandlogo')->__('Add Brand');
    }
}

Location: app/code/local/Digitab/Brandlogo/Helper/Data.php

<?php
class Digitab_Brandlogo_Helper_Data extends Mage_Core_Helper_Abstract {}

Location: app/code/local/Digitab/Brandlogo/controllers/Adminhtml/BrandlogoController.php

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

The main problem is with the way you have written the XML files.

Location: app/code/local/Digitab/Brandlogo/etc

1. app/code/local/Digitab/Brandlogo/etc/config.xml Below is how the code for config.xml must be.

<?xml version="1.0"?>
<config>
    <modules>
        <Digitab_Brandlogo>
            <version>1.0.0</version>
        </Digitab_Brandlogo>
    </modules>
    <global>
        <models />
        <blocks>
            <digitab_brandlogo>
                <class>Digitab_Brandlogo_Block</class>
            </digitab_brandlogo>
        </blocks>
        <resources />
        <extraconfig />
        <helpers>
            <digitab_brandlogo>
                <class>Digitab_Brandlogo_Helper</class>
            </digitab_brandlogo>
        </helpers>
    </global>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>                        
                        <digitab_brandlogo before="Mage_Adminhtml">Digitab_Brandlogo_Adminhtml</digitab_brandlogo>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
               <brandlogo>
                    <file>brandlogo.xml</file>
               </brandlogo>
            </updates>
        </layout>
    </adminhtml>
</config>

2. app/code/local/Digitab/Brandlogo/etc/adminhtml.xml Below is how the code for config.xml must be.

<?xml version="1.0"?>
<config>
    <menu>
        <digitab translate="title" module="digitab_brandlogo">
            <title>Digitab</title>
            <sort_order>110</sort_order>
            <children>
                <brandlogo>
                    <title>Brand Logo</title>
                    <sort_order>1</sort_order>
                    <action>adminhtml/brandlogo/index</action>
                </brandlogo>
            </children>
        </digitab>
    </menu>
</config>

Location: app/design/frontend/adminhtml/default/default/layout/brandlogo.xml

<?xml version="1.0"?> 
<layout version="0.1.0">
    <adminhtml_brandlogo_index>
        <reference name="content">
            <block type="digitab_brandlogo/adminhtml_brandlogo" name="brandlogo" template="test.phtml"/>
        </reference>
    </adminhtml_brandlogo_index> 
</layout>

Location: app/design/frontend/adminhtml/default/default/template/test.phtml

Looks fine.

I have checked this code in my local machine. Find the screenshot here:

enter image description here

Let me know if this works for you.

Note :: FOLLOW THE EXACT NAMING CONVENTION AND FOLDER NAMES AND THE CODE AS MENTIONED HERE in my Answer

Happy Coding...

3
votes

Quite a few things wrong here, I'll go through each file step by step.

Digitab_Brandlogo.xml

All good here.

logo.php

The only thing wrong here is that your filename is different from your classname (logo != slider). Simply change the filename to the classname or vice versa and you should be good on this file. Also, make the first letter of your class and filename uppercase.

IndexController.php

Same thing here as logo.php, you've named the file differently from the class, however this one you'd want to change the filename to the class name as you've used it in a lot of your other files. The filename should be BrandlogoController.php

config.xml

Because you have a block defined, you want to define your blocks under global.

Replace

<blocks />

with this:

<blocks>
    <digitab_brandlogo>
        <class>Digitab_Brandlogo_Block</class>
    </digitab_brandlogo>
</blocks>

Then, under your router, you want to make sure Brandlogo is capitalized like so:

<digitab_brandlogo>
    <use>admin</use>
    <args>
        <module>Digitab_Brandlogo</module>
        <frontName>brandlogo</frontName>
    </args>
</digitab_brandlogo>

adminhtml.xml

Your action is what you want to hit in your controller. The setup for this (on admin controllers) is adminhtml/module_controller_action (if you leave action off it defaults to index), so in this case you want it to be this:

<action>adminhtml/brandlogo_brandlogo</action>

Data.php

All good here.

brandlogo.xml

Your tag needs to have the format adminhtml_module_controller_action so let's change it to the following:

<adminhtml_brandlogo_brandlogo_index>

Then on this line:

<block type="brandlogo/adminhtml_brandlogo" name="brandlogo" template="test.phtml"/>

You are trying to use an imaginary block type. Remember earlier where we named our block either Logo or Slider? This comes into play here, as that should be the file path you use for "type". So it should look like one of the following:

If you chose Slider

<block type="brandlogo/adminhtml_slider" name="brandlogo" template="test.phtml"/>

If you chose Logo

<block type="brandlogo/adminhtml_logo" name="brandlogo" template="test.phtml"/>

test.phtml

All good here.

Hope this helps!