7

First of all I'm trying to load grid container and show container heading. My block file is working fine. Container path is Super->Awesome->Block->Adminhtml->Awesome.php which contains

<?php
class Super_Awesome_Block_Adminhtml_Awesome extends Mage_Adminhtml_Block_Widget_Grid_Container
{
    public function __construct()
    {
        $this->_blockGroup = 'super_awesome';
        $this->_controller = 'adminhtml_awesome';
        $this->_headerText = Mage::helper('super_awesome')->__('Manage');
        parent::__construct();
    }

}

layout file super_awesome.xml

<?xml version="1.0"?>
<layout>
    <adminhtml_example_index>
        <reference name="content">
            <block type="super_awesome/adminhtml_awesome" name="super_awesome"></block>
        </reference>
    </adminhtml_example_index>
</layout>

If I echo something inside public function __construct(), it's showing content but on adding proper __contruct() method as above it's showing a blank page. Do I need to add internal block(Grid.php) also, then my container text will appear? Container block Awesome.php should be changed to Grid.php?

Config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Super_Awesome>
            <version>0.1.0</version>
        </Super_Awesome>
    </modules>
    <admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <super_awesome before="Mage_Adminhtml">Super_Awesome</super_awesome>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>
    <adminhtml>
        <layout>
            <updates>
                <super_awesome>
                    <file>super_awesome.xml</file>
                </super_awesome>
            </updates>
        </layout>
    </adminhtml>
    <global>
        <blocks>
            <super_awesome>
                <class>Super_Awesome_Block</class>
            </super_awesome>
        </blocks>
        <helpers>
            <super_awesome>
                <class>Super_Awesome_Helper</class>
            </super_awesome>
        </helpers>
    </global>
</config>
  • Do you have your Super_Awesome_Block_Adminhtml_Awesome_Grid.php? – Adarsh Khatri Jun 30 '15 at 1:47
3

The code you are adding in your __construct method sets the details for the internal block that I think you are missing.

public function __construct()
    {
        $this->_blockGroup = 'super_awesome';
        $this->_controller = 'adminhtml_awesome';
        $this->_headerText = Mage::helper('super_awesome')->__('Manage');
        parent::__construct();
    }

Those settings are used in the parents _prepareLayout() method as below.

protected function _prepareLayout()
{
    $this->setChild( 'grid',
        $this->getLayout()->createBlock( $this->_blockGroup.'/' . $this->_controller . '_grid',
        $this->_controller . '.grid')->setSaveParametersInSession(true) );
    return parent::_prepareLayout();
}

For you this bit of code will end up as

  $this->getLayout()->createBlock('super_awesome/adminhtml_awesome_grid');

Which means you need to create the block Super_Awesome_Block_Adminhtml_Awesome_Grid which should extend Mage_Adminhtml_Block_Widget_Grid.

Mage_Adminhtml_Block_Poll_Grid could be used as an example for this missing grid block.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.