ZF2 has a nice way to register it's own 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)? 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.
This could easily be done in the onBootstrap
in a Module class.
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);
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.