I’ve been working on getting a new form in the adminhtml for my Magento module. I’m running into a serious issue with actually loading blocks, however. I can load a test block (using a phtml layout) using this code I found in a different stack overflow question (I implement this in the adminhtml controller):
$block = $this->getLayout()->createBlock('coupsmart_coupon/adminhtml_forms');
error_log('The block:' . var_export($block, true));
if($block)
{
$block->setTemplate('test/test.phtml');
error_log(var_export($block->getTemplate(), true));
error_log('The HTML:');
error_log(var_export($block->toHtml(),true));
}
Using a test block, I get back the correct html (found in my adminhtml/default/default/template folder).
However, when I instantiate a grid_container block, it it doesn’t run the if($block){} portion, because the block is false. But in my block class for the grid_container, I have a __constructor() method where I log an output, so it is running the constructor, which means my class instantiation (and naming) is correct.
What can cause a constructor to run on a block but have it still return false, for an Mage_Adminhtml_Block_Widget_Grid_Container class?
If any more code is needed (controller, grid_container block, grid block, config, etc.) is needed, let me know, and I’ll post it up. I just didn’t want to overwhelm with a code overflow that may dilute the question.
EDIT: Grid Container
class Coupsmart_Coupon_Block_Adminhtml_Forms extends
Mage_Adminhtml_Block_Widget_Grid_Container
{
public function __construct()
{
error_log('adminhtml forms (parent) construct');
$this->_controller = 'adminhtml_forms';
$this->_blockGroup = 'coupsmart_coupon';
$this->_headerText = Mage::helper('forms')->__('Coupon Manager');
$this->_addButtonLabel = Mage::helper('forms')->__('Edit Coupon');
parent::__construct();
}
}
The error log in the container above shows up when I instantiate the block.
The returned block can be false if an exception is thrown while it’s instantiated. In your code, this may certainly come from this part :
Mage::helper('forms').In the config.xml file of your module, have you defined the helpers like this ? :
Else, replace
formsby the other code you used in the calls toMage::helper('forms')(from what it seems, this should probably rather looks like this :Mage::helper('coupsmart_coupon'))