I created a new module, in which I am creating a block by the following method in IndexController.php which is at app/code/local/Ashfame/Helloblock/controllers/IndexController.php
class Ashfame_Helloblock_IndexController extends Mage_Core_Controller_Front_Action {
public function indexAction() {
// this works fine
$block = new Ashfame_Helloblock_Block_Helloblock();
echo $block->toHtml();
}
public function layoutAction() {
// this doesn't work
$layout = Mage::getSingleton('core/layout');
$block = $layout->createBlock('ashfame_helloblock/helloblock','root');
var_dump( $block ); // this returns false
echo $block->toHtml();
}
}
My Block class is Ashfame_Helloblock_Block_Helloblock and is at app/code/local/Ashfame/Helloblock/Block/Helloblock.php
Since the $block in layoutAction() is false, PHP throws an error Call to a member function toHtml() on a non-object
On debugging I found that the magento is figuring out the class name wrong. It figure out the class name as mage_Ashfame_helloblock_block inside getGroupedClassName().
What's wrong here?