如何在其他自定义模块的模型文件中调用块函数?

问题描述 投票:0回答:1

我在Magento 2上工作,我想使用其他模块的block函数来获取一些数据。我如何在我的模块的模型文件中调用该模块函数?

magento magento2
1个回答
0
投票

在自定义模块类中调用块类方法的两种方法。

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。

© www.soinside.com 2019 - 2024. All rights reserved.