发生错误 执行期间发生错误;请稍后再试。 附加信息: 的Zend \的ServiceManager \异常\ ServiceNotFoundException的
文件:
C:\wamp\www\zend2book\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:495
消息:
Zend\ServiceManager\ServiceManager::get was unable to fetch or create an instance for UserEditForm
堆栈追踪:
#0 C:\wamp\www\zend2book\module\Users\src\Users\Controller\UserManagerController.php(34): Zend\ServiceManager\ServiceManager->get('UserEditForm')
#1 C:\wamp\www\zend2book\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractActionController.php(83): Users\Controller\UserManagerController->editAction()
#2 [internal function]: Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#3 C:\wamp\www\zend2book\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#4 C:\wamp\www\zend2book\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#5 C:\wamp\www\zend2book\vendor\zendframework\zendframework\library\Zend\Mvc\Controller\AbstractController.php(117): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#6 C:\wamp\www\zend2book\vendor\zendframework\zendframework\library\Zend\Mvc\DispatchListener.php(114): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#7 [internal function]: Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#8 C:\wamp\www\zend2book\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(468): call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#9 C:\wamp\www\zend2book\vendor\zendframework\zendframework\library\Zend\EventManager\EventManager.php(207): Zend\EventManager\EventManager->triggerListeners('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#10 C:\wamp\www\zend2book\vendor\zendframework\zendframework\library\Zend\Mvc\Application.php(309): Zend\EventManager\EventManager->trigger('dispatch', Object(Zend\Mvc\MvcEvent), Object(Closure))
#11 C:\wamp\www\zend2book\public\index.php(17): Zend\Mvc\Application->run()
#12 {main}
这是我来自控制器的编辑操作:
public function editAction()
{
$this->layout('layout/myaccount');
$userTable = $this->getServiceLocator()->get('UserTable');
$user = $userTable->getUser($this->params()->fromRoute('id'));
$form = $this->getServiceLocator()->get('UserEditForm');
$form->bind($user);
$viewModel = new ViewModel(array('form' => $form, 'user_id' => $this->params()->fromRoute('id')));
return $viewModel;
}
我的表单代码
<?php
// filename : module/Users/src/Users/Form/RegisterForm.php
namespace Users\Form;
use Zend\Form\Form;
class UserEditForm extends Form
{
public function __construct($name = null)
{
parent::__construct('Edit User');
$this->setAttribute('method', 'post');
$this->setAttribute('enctype','multipart/form-data');
$this->add(array(
'name' => 'id',
'attributes' => array(
'type' => 'hidden',
),
));
$this->add(array(
'name' => 'name',
'attributes' => array(
'type' => 'text',
'required' => 'required'
),
'options' => array(
'label' => 'Full Name',
),
));
$this->add(array(
'name' => 'email',
'attributes' => array(
'type' => 'email',
'required' => 'required'
),
'options' => array(
'label' => 'Email',
),
));
$this->add(array(
'name' => 'submit',
'attributes' => array(
'type' => 'submit',
'value' => 'Save'
),
));
}
}
如果您需要我添加更多代码。
答案 0 :(得分:0)
找不到UserEditForm
。
很可能您没有在服务管理器配置中定义其位置。
确保定义
'service_manager' => array (
'invokables' => array (
'UserEditForm' => 'Users\Form\RegisterForm'
),
)