如何在 Zend Framework 2 中启用 formselect 视图助手?

How can I enable formselect view helper in Zend Framework 2?

我没有使用完整的 ZF2 安装,只有我指定的模块,包括 zendframework/zend-form

来自 formselect:

use Zend\Form\Element;

$element = new Element\Select('language');
$element->setValueOptions(array(
   '0' => 'French',
    //...
   '3' => 'Chinese'
));

echo $this->formSelect($element);

问题:

在非视图中时 PHP:

PHP error: Call to undefined method formSelect()

在 *.phtml 中查看文件时:

Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException'
with message 'Zend\View\HelperPluginManager::get was unable to fetch 
or create an instance for formselect'

注:

$this->partial() 有效,$this->escapehtml() 也有效,但 $this->formselect() 无效

找到解决方法 - 必须在视图 (phtml) 文件之外完成:

use Zend\Form\View\Helper\FormSelect;

$form = new FormSelect();
$selectHtml = $form->render($element);

//then
echo $selectHtml;

//or from view:
$this->partial($file, array('select' => $selectHtml));