cancel
Showing results for 
Search instead for 
Did you mean: 

Display Grid in Admin Module of Magento

Display Grid in Admin Module of Magento

I am learning Magento module development. I am trying to develop a custom module for Magento Admin panel. I would like to display grid. 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

 

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();
         } 

       protected function _prepareLayout()
       {
         $this->setChild('grid',$this->getLayout()->createBlock( $this->_blockGroup.'/' . $this->_controller . '_grid', $this->_controller . '.grid')->setSaveParametersInSession(true) );
        return parent::_prepareLayout();
       }
}

 

Location: 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('brand_id');
         $this->setDefaultSort('brand_id');
         $this->setDefaultDir('ASC');
         $this->setSaveParametersInSession(true);
         $this->setUseAjax(true);
       } 

       protected function _prepareCollection()
       { 
           $collection = Mage::getResourceModel('digitab_brandlogo/brandlogo_collection'); 
           $this->setCollection($collection);
           return parent::_prepareCollection();
       }

       public function getRowUrl($row)
        {
             return $this->getUrl('digitab_brandlogo_admin/brandlogo/edit',array('id' => $row->getId()));
        } 

       
    protected function _prepareColumns()
    {
        $this->addColumn('brand_id', array(
            'header' => $this->_getHelper()->__('brand_id'),
            'type' => 'number',
            'index' => 'brand_id',
        ));


         $this->addColumn('brand_name',
            array(
                'header'=> $this->__('brand_name'),
                'index' => 'brand_name'
            )
        );          

        return parent::_prepareColumns();
    }


    protected function _getHelper()
    {
        return Mage::helper('digitab_brandlogo');
    }
}


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();
    }

    public function gridAction()
    {
         $this->loadLayout();
         $this->getResponse()->setBody($this->getLayout()->createBlock('digitab_brandlogo/adminhtml_brandlogo')->toHtml());
    }
}

 

 

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>           
        <helpers>
            <digitab_brandlogo>
                <class>Digitab_Brandlogo_Helper</class>
            </digitab_brandlogo>
        </helpers>
        <blocks>
            <brandlogo>
               <class>Digitab_Brandlogo_Block</class>
            </brandlogo>
        </blocks>
        <models>
            <brandlogo>
                <class>Digitab_Brandlogo_Model</class>                
                <resourceModel>digitab_brandlogo_resource</resourceModel>
            </brandlogo>
            <digitab_brandlogo_resource>
                <class>Digitab_Brandlogo_Model_Resource</class>
                <entities>
                    <brandlogo>
                        <table>digitab_brandlogo</table>
                    </brandlogo>
                </entities>
            </digitab_brandlogo_resource>
        </models>
        <resources>
    <brandlogo_setup>
        <setup>
            <brandlogo>digitab_brandlogo</brandlogo>
        </setup>
        <connection>
            <use>core_setup</use>
        </connection>
    </brandlogo_setup>
    <brandlogo_write>
        <connection>
            <use>core_write</use>
        </connection>
    </brandlogo_write>
    <brandlogo_read>
        <connection>
            <use>core_read</use>
        </connection>
    </brandlogo_read>
     </resources>
    </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>


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>adminhtml/brandlogo/index</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/code/local/Digitab/Brandlogo/Model/Brandlogo.php

 

<?php
class Digitab_Brandlogo_Model_Brandlogo extends Mage_Core_Model_Abstract
{
    protected function _construct()
    {         
        parent::_construct();
        $this->_init('digitab_brandlogo/brandlogo');
    }  
}

 

location: app/code/local/Digitab/Brandlogo/Model/Resource/Brandlogo.php

 

 

<?php
class Digitab_Brandlogo_Model_Resource_Brandlogo extends Mage_Core_Model_Resource_Db_Abstract
{
    protected function _construct()
    {  
        $this->_init('digitab_brandlogo/brandlogo','brand_id');
    }  
}

 

location:app/code/local/Digitab/Brandlogo/Model/Resource/Brandlogo/Collection.php

 

 

<?php
class Digitab_Brandlogo_Model_Resource_Brandlogo_Collection extends Mage_Core_Model_Resource_Db_Collection_Abstract
{
    protected function _construct()
    {  
        parent::_construct();
        $this->_init('digitab_brandlogo/brandlogo');
    }  
}

 

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

 

brandlogo.xml

 

<?xml version="1.0"?> 
<layout version="0.1.0">
    <adminhtml_brandlogo_index>
        <reference name="content">
            <block type="brandlogo/adminhtml_brandlogo" name="brandlogo" />
        </reference>
    </adminhtml_brandlogo_index> 
</layout>

 

I am getting a blank white page when I am clicking on Brandlogo menu of Digitab.

 

Could anyone help me to display a grid??

 

Thanks

5 REPLIES 5

Re: Display Grid in Admin Module of Magento

Hi @foysal

 

If you enable error reporting then you will see following error 

 

Fatal error: Class 'Mage_Brandlogo_Helper_Data' not found in \app\Mage.php on line 520

 

You need following fixes :

 

1) config.xml (use Digitab_Brandlogo not digitab_brandlogo)

 

<modules>
        <Digitab_Brandlogo>
            <version>1.0.0</version>
        </Digitab_Brandlogo>
</modules>

2)In Digitab_Brandlogo_Block_Adminhtml_Brandlogo file

 

Use following for helper

 

$this->_headerText = Mage::helper('digitab_brandlogo')->__('Brand Logo Manager');
$this->_addButtonLabel = Mage::helper('digitab_brandlogo')->__('Add Brand');

As you have used following in config.xml

 

<helpers>
<digitab_brandlogo> <!- This node name should be used for helper -->
<class>Digitab_Brandlogo_Helper</class>
</digitab_brandlogo>
</helpers>

 

 

---
Problem Solved Click Accept as Solution!:Magento Community India Forum

Re: Display Grid in Admin Module of Magento

Thanks @Mukesh Tiwari for your valuable reply.  I enabled error reporting using below code in index.php.

Mage::setIsDeveloperMode(true);

ini_set('display_errors', 1);

error_reporting(E_ALL);

But I could not see any error.

I implemented your solution but the issue is not solved, it is as like previous, I am seeing blank page with menus of Admin Panel. May be the Grid is not loading, what is I am trying to do.

I found below error in exception.log file.

exception 'Mage_Core_Exception' with message 'Invalid block type: Digitab_Brandlogo_Block_Brandlogo' in /home3/theaid/public_html/demo/app/Mage.php:595

Could you help me in this regard ??

Thanks

 

Re: Display Grid in Admin Module of Magento

Hi @foysal

 

In your BrandlogoController.php file use following.

 

$this->getResponse()->setBody($this->getLayout()->createBlock('brandlogo/adminhtml_brandlogo')->toHtml());  

instead of

$this->getResponse()->setBody($this->getLayout()->createBlock('digitab_brandlogo/adminhtml_brandlogo')->toHtml());
---
Problem Solved Click Accept as Solution!:Magento Community India Forum

Re: Display Grid in Admin Module of Magento

Hi @foysal

 

In your BrandlogoController.php file use following.

 

$this->getResponse()->setBody($this->getLayout()->createBlock('brandlogo/adminhtml_brandlogo')->toHtml());  

instead of

$this->getResponse()->setBody($this->getLayout()->createBlock('digitab_brandlogo/adminhtml_brandlogo')->toHtml());
---
Problem Solved Click Accept as Solution!:Magento Community India Forum

Re: Display Grid in Admin Module of Magento

Thanks @Mukesh Tiwari for your reply. I modified my code as per your instruction, but it is not working. The result is as like previous. Thanks.