我在 composer.json 中指定了 zend 组件列表
"zendframework/zend-xmlrpc": "2.0.*",
"zendframework/zend-config": "2.0.*",
"zendframework/zend-log": "2.0.*",
"zendframework/zend-db": "2.0.*",
"zendframework/zend-inputfilter": "2.0.*",
"zendframework/zend-json": "2.0.*",
"zendframework/zend-form": "2.0.*",
"zendframework/zend-mvc" : "2.0.*",
"zendframework/zend-session" : "2.0.*",
"zendframework/zend-view" : "2.0.*"
但是当我尝试在视图脚本中输出表单时:
<?php
use Zend\Form\Form;
use Zend\Form\Element;
$form = new Form();
$form->setAttribute('action', '/contact/process');
$form->setAttribute('method', 'post');
$form->prepare();
echo $this->form()->openTag($form);
echo $this->form()->closeTag();
?>
我得到例外:
ServiceNotFoundException: Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for form
#in /var/www/projectdir/vendor/zendframework/zend-servicemanager/Zend/ServiceManager/ServiceManager.php line 452
#at ServiceManager->get('form', true) in /var/www/projectdir/vendor/zendframework/zend-servicemanager/Zend/ServiceManager/AbstractPluginManager.php line 110
#at AbstractPluginManager->get('form', null) in /var/www/projectdir/vendor/zendframework/zend-view/Zend/View/Renderer/PhpRenderer.php line 340
#at PhpRenderer->plugin('form') in /var/www/projectdir/vendor/zendframework/zend-view/Zend/View/Renderer/PhpRenderer.php line 359
#at PhpRenderer->__call('form', array()) in /var/www/projectdir/views/editWorker.phtml line 19
#at PhpRenderer->form() in /var/www/projectdir/views/editWorker.phtml line 19
.....
但是其他视图助手,例如 $this->htmlList($items) 可以正常工作