Magento block construct - use _construct or __construct?

I am a bit confused. I read an article by Alan Storm on β€œMagento Life Cycle Methods , ” and as I understand it, you should use the protected _construct() method to initialize the block. In my case, I just want to set the correct block template. So I guess I should use

 protected function _construct() { parent::_construct(); $this->setTemplate('stenik/qaforum/forum.phtml'); } 

However, when I look at the blocks of some of the main Magento modules, they seem to use the php __construct method to do this. For example Mage_Poll_Block_Poll , Mage_ProductAlert_Block_Price , Mage_Rating_Block_Entity_Detailed , Mage_Review_Block_Form

Although both methods really work, I would like to know how to do it correctly.

+6
source share
1 answer

Ultimately, the academic but correct way to do this is to override the Magento constructor, i.e. _construct at the request of the main command in Mage_Core_Block_Abstract :

 /** * Internal constructor, that is called from real constructor * * Please override this one instead of overriding real __construct constructor * */ protected function _construct() { /** * Please override this one instead of overriding real __construct constructor */ } 
+8
source

Source: https://habr.com/ru/post/952049/


All Articles