I’m following this tutorial http://codemagento.com/2011/03/creating-custom-magento-reports/ creating the simple report module. I have all the code and XML in place but I’m receiving this error
2012-05-31T21:48:43+00:00 ERR (3): Recoverable Error: Argument 1 passed to Mage_Adminhtml_Controller_Action::_addContent() must be an instance of Mage_Core_Block_Abstract, boolean given, called in /var/www/magento/app/code/local/Super/Awesome/controllers/Adminhtml/Report/ExampleController.php on line 22 and defined in /var/www/magento/app/code/core/Mage/Adminhtml/Controller/Action.php on line 112
The structure looks like this
Super
|_ Awesome
|_Block
| |_Adminhtml
| |_Report
| |_Simple
| | |_Grid.php
| |_Simple.php
|_controllers
| |_Adminhtml
| |_Report
| |_ExampleController.php
|_etc
| |_adminhtml.xml
| |_config.xml
|_Helper
| |_Data.php
|_Model
|_Mysql4
| |_Report
| | |_Simple
| | |_Collection.php
| |_Simple.php
|_Simple.php
I assume that it is not finding the block code but why?
Edit
<?xml version="1.0"?>
<config>
<modules>
<Super_Awesome>
<version>0.1.0</version>
</Super_Awesome>
</modules>
<admin>
<!--
Here we are telling the Magento router to look for the controllers in the Super_Awesome_controllers_Adminhtml before we look in the
Mage_Adminhtml module for all urls that begin with /admin/controller_name
-->
<routers>
<adminhtml>
<args>
<modules>
<awesome before="Mage_Adminhtml">Super_Awesome_Adminhtml</awesome>
</modules>
</args>
</adminhtml>
</routers>
</admin>
<models>
<awesome>
<class>Super_Awesome_Model</class>
<resourceModel>awesome_mysql4</resourceModel>
</awesome>
<awesome_mysql4>
<class>Super_Awesome_Model_Mysql4</class>
<entities>
<simple>
<table>super_awesome_example_simple</table>
</simple>
</entities>
</awesome_mysql4>
</models>
<global>
<resources>
<awesome_setup>
<setup>
<module>Super_Awesome</module>
<class>Super_Awesome_Model_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</awesome_setup>
<awesome_write>
<connection>
<use>core_write</use>
</connection>
</awesome_write>
<awesome_read>
<connection>
<use>core_read</use>
</connection>
</awesome_read>
</resources>
<helpers>
<awesome>
<class>Super_Awesome_Helper</class>
</awesome>
</helpers>
</global>
</config>
File: app/code/local/Super/Awesome/Block/Adminhtml/Report/Simple.php
class Super_Awesome_Block_Adminhtml_Report_Simple extends Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
$this->_blockGroup = 'awesome';
$this->_controller = 'adminhtml_report_simple';
$this->_headerText = Mage::helper('awesome')->__('Simple Report');
parent::__construct();
$this->_removeButton('add');
}
}
When you (or Magento) uses the following code
you’re saying
Magento needs to know the base name of the class to use for blocks from the awesome group. If you don’t tell Magento what the base name of the class to use for blocks from the awesome group, it can’t instantiate a block. That’s why calls to the method are returning
falseinstead of returning a block object, and that’s why you’re getting that exception.You need to “turn on” blocks for your module by adding a section to your configuration. Based on your example above, you’ve already done something similar for helper classes.
That’s why your module can use helper classes. You just need to do the same thing for block classes
That and a cache clear should set you right. If it doesn’t work, trace
createBlockto determine where it’s looking in the configuration for theblocks/awesomenode. That’s usually enough for me to notice the typo I’ve been starting at for two hours.