Monday, 19 August 2013

Magento Block construct - use _construct or __construct?

Magento Block construct - use _construct or __construct?

I am a little bit confused. I read Alan Storm's excellent article about
Magento Block Lifecycle Methods and as far as I understand one should be
using the protected _construct() method to initialize the block. In my
case I just want to set the right block template. So I assume I should be
using
protected function _construct()
{
parent::_construct();
$this->setTemplate('stenik/qaforum/forum.phtml');
}
However, when I look at the blocks of some of the core Magento modules,
they seem to use the php __construct method to do it. For example
Mage_Poll_Block_Poll, Mage_ProductAlert_Block_Price,
Mage_Rating_Block_Entity_Detailed, Mage_Review_Block_Form
Although both ways actually work, I'd like to know what is the right way
to do it.

No comments:

Post a Comment