magento 2相当于Mage :: helper('core') - >?

时间:2017-04-10 08:15:18

标签: magento2 helper mage

magento 2相当于Mage :: helper('core') - > ?

1 个答案:

答案 0 :(得分:0)

Mage静态方法不再存在,您必须使用依赖注入来获取帮助程序实例,例如在您的模型中:

<?php
namespace Mycompany\Mymodule\Model;
use Mycompany\Mymodule\Helper\Data;
class Custom {

    private $helper;

    public function __construct(
        Data $helper
    ) {
        $this->helper = $helper;
    }

    public function myMethod() {
        $this->helper->helperMethod();
    }
}

您可以在块等中使用相同的系统,也可以使用您想要使用的现有助手。