网格未出现在Magento的自定义管理模块中

nai*_*vin 5 magento

我正在尝试在magento admin中创建自定义模块.我已经达到了将新链接添加到菜单并通过单击它的程度,我可以导航到模块控制器的索引操作.但是在这里我看不到网格,只显示了标题文本和块结构中添加的按钮.

我可以看到,由于这个块扩展了Mage_Adminhtml_Block_Widget_Grid_Container类,它本身会将此模块中的网格块添加为其子节点.

并且包含Grid.php,我通过在overriden _prepareColumns方法中打印出一些内容来验证.

我在这里错过了什么?

这些是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()));
    }
}
Run Code Online (Sandbox Code Playgroud)

谢谢

PS.我试过刷缓存但没有运气

clo*_*eek 1

从记忆中我认为_prepareColumns()之前被调用过_prepareCollection(),所以如果集合中存在错误,即使您已经确认了 columns 方法,网格也不会被渲染。

在尝试parent::_prepareCollection()根据集合getSize()getSelectCountSql()方法估计页数时,我经常忘记检查它们是否产生了合理的结果,这让我很困惑。确保所有日志记录均已打开并将以下内容放入您的.htaccess文件中:

php_flag display_errors on
SetEnv MAGE_IS_DEVELOPER_MODE true
Run Code Online (Sandbox Code Playgroud)

尝试查看使用以下命令生成了什么查询:

Mage::log((string)$collection->getSelect());
Mage::log((string)$collection->getSelectCountSql());
Run Code Online (Sandbox Code Playgroud)