Use another module in our custom helper in zend fr

2019-05-20 13:11发布

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);
            }
        )
    );
}

1条回答
神经病院院长
2楼-- · 2019-05-20 13:29

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?

It probably isn't a ViewHelper, because if it would be, you could access it like you did.

If it's a Service, you'll get it from the ServiceManager

return new \Base\View\Helper\ImageLib(
    $sm->getServiceLocator()->get('WebinoImageThumb')
);

If it's a ControllerPlugin, you'll get it from the ControllerPluginManager

return new \Base\View\Helper\ImageLib(
    $sm->getServiceLocator()->get('ControllerPluginManager')->get('WebinoImageThumb')
);
查看更多
登录 后发表回答