Grid doesn't appear in custom admin module in Magento

后端 未结 3 1053
轻奢々
轻奢々 2021-01-19 03:23

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 ind

相关标签:
3条回答
  • 2021-01-19 04:08

    Looks like you have the grid blocks set up correctly. However, you still need to load the grid into the layout and render it. This can either be done in the adminhtml layout xml or in the controller.

    In your /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>
    

    In your controller:

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

    Please note that you have to modify the above to your particular implementation. I think the layout xml is harder to comprehend initially than the programmatic instantiation in the controller, however, in the long run, it leads to less code bloat.

    0 讨论(0)
  • 2021-01-19 04:25

    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.

    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());
    
    0 讨论(0)
  • 2021-01-19 04:26

    Just had a quick view and the only thing I can see in your code is:

    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 讨论(0)
提交回复
热议问题