Magento: Fatal error: Call to a member function toHtml() on a non-object -


i error when try load block in controller

fatal error: call member function tohtml() on non-object in ... on line ...

this config.xml

<blocks>   <auction>     <class>custom_auction_block</class>   </auction> </blocks> 

i call block code in controller:

$this->loadlayout(); $autoupdate= $this->getlayout()->getblock('auction.auto.update')->tohtml(); mage::register('referrer_url', $this->_getrefererurl()); $response['autoupdate'] = $autoupdate; 

i create block in auction/block/product/autoupdate.php

class custom_auction_block_product_autoupdate extends mage_core_block_template{    

}

here layout

<block type="auction/product_view" name="auction_view" template="auction/catalog/product/view.phtml">         <block type="auction/product_autoupdate" name="auction.auto.update" as="auction_autoupdate" template="auction/catalog/product/autoupdate.phtml"/>   </block> 

i try add "protected function _tohtml()" in block too.. doesn't work.

anyone can me? fyi, use magento 1.6.2.0 thx in advance :)

your call

$this->getlayout()->getblock('auction.auto.update') 

is not returning block object. that's either because magento hasn't run layout xml update particular page you're running code, or because can't instantiate block class alias auction/product_autoupdate.

my educated guess later, , code , configuration samples imprecise pinpoint reason. try running following code

$b = $this->getlayout()->createblock('auction/product_autoupdate'); var_dump($b); 

if var_dump doesn't dump object, means configuration incorrect. start tracing code in createblock method until point references configuration determine block's php class. should tell what's wrong configuration. luck.


Comments