Magento – Why isn’t magento finding the adminhtml grid block

adminhtmlblocksgrid

I'm trying to build my first admin grid.

The tutorial I'm following is http://inchoo.net/magento/how-to-create-a-custom-grid-from-scratch/

The routing-to-the-controller part is working. When I open my URL, I see the title set using $this->title().

controllers/Adminhtml/Shipments/ReportController.php

    $block = $this->getLayout()
        ->createBlock('ebuynow_ebnreports/adminhtml_shipments_report');
    $this->_addContent($block);

Block/Adminhtml/Shipments/Report.php, Ebuynow_Ebnreports_Adminhtml_Shipments_Report::__construct()

    $this->_blockGroup = 'ebuynow_ebnreports';
    $this->_controller = 'adminhtml_shipments_report';
    $this->_headerText = Mage::helper('ebuynow_ebnreports')
        ->__('sum headertext');
    parent::__construct();
    $this->removeButton('add');

And the grid file is located Block/Adminhtml/Shipments/Report/Grid.php and has class Ebuynow_Ebnreports_Block_Adminhtml_Shipments_Report_Grid. I've been looking at this for a while, and it all looks like it matches up with the inchoo tutorial code.

When I open the page with developer mode turned on, I get this error

Recoverable Error: Argument 1 passed to Mage_Adminhtml_Controller_Action::_addContent()
must be an instance of Mage_Core_Block_Abstract, boolean given

The createBlock() call is not able to find the block using that string and I don't see why.

If more information is needed I can add more code, I just figured this was where the error was.

Possibly relevant: I followed the execution path of createBlock() to see what it was looking for given the string ebuynow_ebnreports/adminhtml_shipments_report. In Mage/Core/Model/Config.php ::getGroupedClassName(), I echoed $className at the end, before the return and for this: Mage_Ebuynow_Ebnreports_Block_Adminhtml_Shipments_Report

It seems to be prefixing my block class name with Mage_. Not sure if that's normal or not but seems odd. I tried adding Mage_ to my actual block's class name and it didn't help.

Best Answer

The solution was to add the following block in config.xml:

    <blocks>
        <ebuynow_ebnreports>
            <class>Ebuynow_Ebnreports_Block</class>
        </ebuynow_ebnreports>
    </blocks>
Related Topic