0

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

表单选择

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()

4

1 回答 1

1

找到了解决方法 - 必须在视图(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));
于 2015-09-29T16:59:37.637 回答