首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Magento构造-使用_construct还是__construct?

Magento构造-使用_construct还是__construct?
EN

Stack Overflow用户
提问于 2013-08-19 16:34:46
回答 1查看 4.9K关注 0票数 7

我有点糊涂。我读了Alan关于Magento块生命周期方法的优秀文章,据我所知,应该使用protected _construct()方法初始化块。在我的例子中,我只想设置正确的块模板。所以我想我应该用

代码语言:javascript
复制
protected function _construct()
{
    parent::_construct();
    $this->setTemplate('stenik/qaforum/forum.phtml');
}

但是,当我查看一些Magento核心模块的块时,它们似乎使用了php __construct方法来实现它。例如Mage_Poll_Block_PollMage_ProductAlert_Block_PriceMage_Rating_Block_Entity_DetailedMage_Review_Block_Form

虽然这两种方法都有效,但我想知道什么是正确的方法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-08-19 16:42:08

它最终是学术性的,但正确的方法是根据核心团队在_construct中的请求覆盖Magento构造函数,即Mage_Core_Block_Abstract

代码语言:javascript
复制
/**
 * 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
     */
}
票数 10
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/18318781

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档