我在 magento admin 中创建了一个自定义模块。问题是grid.php从Mage_Adminhtml_Block_Widget_Grid扩展不显示网格(仅显示按钮和标题文本)。grid.php 的内容:
class Ha_Hvdmodule_Block_Adminhtml_Information_Grid extends Mage_Adminhtml_Block_Widget_Grid{
public function _construct(){
parent::_construct();
$this->setId('informationGrid');
$this->setDefaultSort('id');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection(){
$collection = Mage::getModel('hvdmodule/information')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns(){
$this->addColumn('id', array(
'header' => Mage::helper('hvdmodule')->__('ID'),
'align' => 'right',
'width' => '10px',
'index' => 'id',
));
$this->addColumn('name', array(
'header' => Mage::helper('hvdmodule')->__('Name'),
'align' => 'left',
'width' => '15px',
'index' => 'name',
));
$this->addColumn('content', array(
'header' => Mage::helper('hvdmodule')->__('Content'),
'align' => 'left',
'width' => '20px',
'index' => 'content',
));
return parent::_prepareColumns();
}
}
?>
内容布局:
<?xml version="1.0"?>
<layout>
<hvdmodule_adminhtml_information_index>
<reference name="content">
<block type="hvdmodule/adminhtml_information" name="information"/>
</reference>
</hvdmodule_adminhtml_information_index>
</layout>
内容控制器:
class Ha_Hvdmodule_Adminhtml_InformationController extends Mage_Adminhtml_Controller_Action{
public function indexAction(){
$this->loadLayout();
$this->renderLayout();
}
}