[英]Zend Framework 2: Registering multiple custom view helpers externally
ZF2 has a nice way to register it's own Form View Helpers . ZF2有一个不错的方法来注册自己的Form View Helpers 。
Let's say I've got my own external library and have a folder with several custom view helpers. 假设我有自己的外部库,并且有一个包含几个自定义视图助手的文件夹。 In which way could I use such a "HelperConfig"-file as Zend Form does (see above)?
我可以像Zend Form一样使用这种“ HelperConfig”文件(见上文)吗? How would I register it in my Application?
如何在我的应用程序中注册?
If you have a class that implements Zend\\ServiceManager\\ConfigInterface
(just like the example you provided) all you need is to pass in a ServiceManager instance. 如果您有一个实现
Zend\\ServiceManager\\ConfigInterface
(就像您提供的示例一样),那么您只需传递ServiceManager实例即可。
This could easily be done in the onBootstrap
in a Module class. 这可以很容易地在Module类的
onBootstrap
中完成。
namespace MyModule;
use Some\Other\Namespace\MyCustomViewHelperConfig;
use Zend\EventManager\EventInterface;
use Zend\ModuleManager\Feature\BootstrapListenerInterface;
class Module implements BootstrapListenerInterface
{
public function onBootstrap(EventInterface $event)
{
$application = $event->getApplication();
$serviceManager = $application->getServiceManager();
$viewHelperManager = $serviceManager->get('ViewHelperManager');
$viewHelperConfig = new MyCustomViewHelperConfig();
$viewHelperConfig->configureServiceManager($viewHelperManager);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.