网格未出现在Magento的自定义管理模块中 [英] Grid doesn't appear in custom admin module in Magento
问题描述
我正在尝试在magento admin中创建自定义模块.我已经到达将新链接添加到菜单的位置,然后单击它,可以导航到模块控制器的index动作.但是在这里我看不到网格,只有标题文本和已添加到块结构中的按钮出现.
I am trying to create a custom module in magento admin. I have reached the point where a new link has been added to the menu and by clicking on it, I can navigate to the index action of the controller of the module. But here I cannot see the grid, only the header text and the button which has been added in the block construct appear.
我可以看到,由于此块扩展了Mage_Adminhtml_Block_Widget_Grid_Container
类,因此它本身将在该模块内部添加网格块作为其子级.
I can see that since this block extends the Mage_Adminhtml_Block_Widget_Grid_Container
class, it will by itself add the grid block inside this module as its child.
并且包含了Grid.php,我通过在重写的_prepareColumns
方法中打印出某些内容进行了验证.
And the Grid.php is included which I verified by printing out something in the overriden _prepareColumns
method.
我在这里想念什么?
这些是Grid.php文件的内容
These are the contents of the Grid.php file
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.我曾尝试刷新缓存,但没有运气
PS. I have tried flushing the cache but no luck
推荐答案
从内存中我认为_prepareColumns()
在_prepareCollection()
之前被调用,因此即使集合中有错误,网格也不会被渲染,即使您有确认了列法.
From memory I think _prepareColumns()
is called before _prepareCollection()
so if there is an error in the collection the grid won't get rendered even though you have confirmed the columns method.
parent::_prepareCollection()
的一部分试图从集合的getSize()
和getSelectCountSql()
方法估计页面数,我经常忘记检查那些页面是否产生了使我绊倒的理智结果.确保所有日志记录均已打开,并将以下内容放入您的.htaccess
文件:
Part of parent::_prepareCollection()
tries to estimate the number of pages from the collection's getSize()
and getSelectCountSql()
methods, I often forget to check those are producing sane results which trips me up. Make sure all logging is turned on and put the following in your .htaccess
file:
php_flag display_errors on
SetEnv MAGE_IS_DEVELOPER_MODE true
尝试查看这些命令正在生成什么查询:
Try seeing what query is being generated with these commands:
Mage::log((string)$collection->getSelect());
Mage::log((string)$collection->getSelectCountSql());
这篇关于网格未出现在Magento的自定义管理模块中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!