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> </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
No comments:
Post a Comment