Mage::helper('core')-> 的 magento 2 等价物是什么?
What would the magento 2 equivalent of Mage::helper('core')->?
magento 2 相当于 Mage::helper('core')-> ?
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();
}
}
您可以在 Blocks 等中使用相同的系统,以及您想要使用的现有助手。
magento 2 相当于 Mage::helper('core')-> ?
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();
}
}
您可以在 Blocks 等中使用相同的系统,以及您想要使用的现有助手。