我正嘗試在magento admin中創建一個自定義模塊。我已經達到了一個新的鏈接添加到菜單,並點擊它,我可以導航到該模塊的控制器的索引行動。但是在這裏我看不到網格,只有標題文本和塊結構中添加的按鈕出現。網格不會出現在Magento中的自定義管理模塊中
我可以看到,由於該塊擴展了Mage_Adminhtml_Block_Widget_Grid_Container
類,它本身會將此模塊內部的網格塊添加爲其子級。
而且包含了Grid.php,我通過在覆蓋範圍012b方法中打印出某些東西來驗證。
我在這裏錯過了什麼?
這些都是Grid.php文件的內容
class Book_Brands_Block_Adminhtml_Brands_Grid extends Mage_Adminhtml_Block_Widget_Grid {
public function __construct() {
parent::__construct();
$this->setId('brandsGrid');
$this->setDefaultSort('brands_id');
$this->setDefaultDir('ASC');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection() {
$collection = Mage::getModel('brands/brands')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns() {
$this->addColumn('brands_id', array(
'header' => Mage::helper('brands')->__('ID'),
'align' =>'right',
'width' => '50px',
'index' => 'brands_id',
));
$this->addColumn('title', array(
'header'=> Mage::helper('brands')->__('Title'),
'align' =>'left',
'index' => 'title',
));
$this->addColumn('status', array(
'header'=> Mage::helper('brands')->__('Status'),
'align' => 'left',
'width' => '80px',
'index' => 'status',
'type' => 'options',
'options' => array(
1 => 'Enabled',
2 => 'Disabled',
),
));
$this->addColumn('action', array(
'header' => Mage::helper('brands')->__('Action'),
'width' => '100',
'type' => 'action',
'getter' => 'getId',
'actions' => array(
array(
'caption' => Mage::helper('brands')->__('Edit'),
'url' => array('base'=> '*/*/edit'),
'field' => 'id'
)
),
'filter' => false,
'sortable' => false,
'index' => 'stores',
'is_system' => true,
));
return parent::_prepareColumns();
}
public function getRowUrl($row) {
return $this->getUrl('*/*/edit', array('id' => $row->getId()));
}
}
感謝
PS。我已經嘗試刷新緩存但沒有運氣
是有你說_prepareCollection問題。將display_errors標誌設置爲真有幫助。萬分感謝! – naiquevin 2011-04-12 06:04:31
@naiquevin你在_prepareCollection中有什麼問題?我有類似的問題。在我的Grid類中,__construct函數工作正常。但是,我的代碼不會去_prepareCollection函數。 – 2011-10-05 04:08:46