magento 2相当于Mage :: helper('core') - > ?
答案 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();
}
}
您可以在块等中使用相同的系统,也可以使用您想要使用的现有助手。