How to use a custom form view helper in Zend Framework 2?

两盒软妹~` 提交于 2019-12-01 08:25:32

Although Andrews answer works, it's not necessary, just use the default view helper name and map it to your helper class, the application will then use your helper instead

public function getViewHelperConfig() {
    return array(
        'invokables' => array(
            'formmulticheckbox' => 'MyNamespace\Form\View\Helper\FormMultiCheckbox',
        ),                
    );
}
Andrew

here's an example of overriding a view helper:

http://ctrl-f5.net/php/zf2-servicemanager-custom-viewhelpers/


Example:

class Module {

    public function onBootstrap(MvcEvent $mvcEvent)
    {
        $application = $mvcEvent->getApplication();
        $serviceManager = $application->getServiceManager();
        $viewHelperManager = $serviceManager->get('ViewHelperManager');
        $viewHelperManager->setInvokableClass('formmulticheckbox', 'MyNamespace\Form\View\Helper\FormMultiCheckbox');
    }
    ...
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!