Magento管理模块中的显示网格


Display Grid in Admin Module of Magento

我正在学习Magento模块的开发。我正在尝试为Magento管理面板开发一个自定义模块。我想显示网格。我的代码如下

位置:应用程序/etc/模块

Digitab_Brandlogo.xml

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

位置: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('digitab_brandlogo')->__('Brand Logo Manager');
            $this->_addButtonLabel = Mage::helper('digitab_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();
       }
    }

位置: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');
    }
}

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

位置:应用程序/代码/本地/数字标签/品牌标识等

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>

位置:应用程序/代码/本地/数字标签/品牌标识等

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>

位置:应用程序/代码/本地/数字标签/品牌标志/助手

Data.php

<?php
class Digitab_Brandlogo_Helper_Data extends Mage_Core_Helper_Abstract
{
}

位置: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');
    }  
}

位置: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');
    }  
}

位置: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');
    }  
}

位置: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>

我在异常中发现错误。日志如下所示

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

当我点击Digitab的Brandlogo菜单时,我得到了一个空白的白色页面。

有人能帮我显示一个网格吗??

感谢

1.助手在app/code/local/Digitab/Brandlogo/Block/Adminhtml/Brandlogo.php 中使用方式错误

像这样使用

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

而不是

$this->_headerText = Mage::helper('brandlogo')->__('Brand Logo Manager');
  1. 您没有任何资源的安装文件