The grid does not appear in the user admin module in Magento

I am trying to create my own module in magento admin. I got to the point that a new link was added to the menu, and by clicking on it, I can go to the index action of the module controller. But here I do not see the grid, only the title text and the button added to the block structure appear.

I see that since this block extends the class Mage_Adminhtml_Block_Widget_Grid_Container, it will itself add a grid block inside this module as its child.

And Grid.php is included, which I checked by printing something in the overriden method _prepareColumns.

What am I missing here?

This is 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()));
    }
}

thank

PS. I tried to clear the cache but no luck

+5
source share
3

, _prepareColumns() _prepareCollection(), , , , .

parent::_prepareCollection() getSize() getSelectCountSql(), , , . , .htaccess :

php_flag display_errors on
SetEnv MAGE_IS_DEVELOPER_MODE true

, :

Mage::log((string)$collection->getSelect());
Mage::log((string)$collection->getSelectCountSql());
+1

, . . adminhtml xml, .

/app/design/adminhtml/../layout/brands.xml:

<?xml version="1.0"?>    
<layout>
        <brands_index_index>
            <reference name="content">
                <block type="brands/brands_grid" name="brands_grid"></block>
            </reference>
        </brands_index_index>
</layout>

:

public function indexAction()
{
    $this->loadLayout();
    $this->_addContent(
        $this->getLayout()->createBlock('brands/brands_grid','brands')
    );
    $this->renderLayout();
}

, . , xml , , .

+1

, , :

protected function _prepareCollection() {       
        $collection = Mage::getModel('brands/brands')->getCollection();
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

//Try to use it like this:
protected function _prepareCollection() {       
        $collection = Mage::getModel('brands/brands')->getCollection();
        $this->setCollection($collection);
        parent :: _ prepareCollection ();
        return $ this;
    }
0
source

All Articles