我在Magento 2上工作,我想使用其他模块的block函数来获取一些数据。我如何在我的模块的模型文件中调用该模块函数?
在自定义模块类中调用块类方法的两种方法。
1)使用构造函数的依赖性,如
public function __construct(Namespace\ModuleName\Helper\Data $helper)
{
$this->helper = $helper;
}
public function MyFunction()
{ $this->helper->HelperDemo();
}
2)使用方法依赖公共函数execute(Namespace/ModuleName/Helper/Data $helper) { $helper->HelperDemo(); }。
更多细节请访问以下链接https:/devdocs.magento.comguidesv2.3extension-dev-guidedepend-inj.html。