在zend Framework 2中的自定义帮助程序中使用另一个模块 [英] Use another module in our custom helper in zend framework 2
问题描述
我想在我的自定义帮助程序中使用WebinoImageThumb模块,但是当我想在帮助程序工厂中创建此模块的实例时,出现此错误:
I want to use WebinoImageThumb moudle in my custom helper , but when I want to create an instance of this module in helper factories I got this error :
Zend\View\HelperPluginManager::get was unable to fetch or create an instance for WebinoImageThumb
但是我可以毫无问题地访问控制器中的实例.
But I can access to an instance in my controller without any problem.
这是我得到错误的代码:
This is the code I get error in :
public function getViewHelperConfig()
{
return array(
'factories' => array(
'ImageLib' => function ($sm)
{
$WebinoImageThumb = $sm->get('WebinoImageThumb');
return new \Base\view\helper\ImageLib($WebinoImageThumb);
}
)
);
}
推荐答案
遗漏的问题是:WebinoImageThumb
是哪种输入.是 ViewHelper ,是 ControllerPlugin 还是服务?
The question that's left out is: What kind of entry is WebinoImageThumb
. Is it a ViewHelper, is it a ControllerPlugin or is it a Service?
它可能不是ViewHelper ,因为如果是这样,您可以像使用它那样进行访问.
It probably isn't a ViewHelper, because if it would be, you could access it like you did.
如果它是服务,则可以从ServiceManager中获取它
If it's a Service, you'll get it from the ServiceManager
return new \Base\View\Helper\ImageLib(
$sm->getServiceLocator()->get('WebinoImageThumb')
);
如果它是 ControllerPlugin ,则可以从ControllerPluginManager
return new \Base\View\Helper\ImageLib(
$sm->getServiceLocator()->get('ControllerPluginManager')->get('WebinoImageThumb')
);
这篇关于在zend Framework 2中的自定义帮助程序中使用另一个模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!