在身份验证时,我收到一条错误消息“提供给 DbTable 的参数未能生成有效的 sql 语句,请检查表名和列名的有效性。 ”我的登录控制器代码是
$form= new login();
$request=$this->getRequest();
if ($request->isPost())
{
$formValidator = new rotaryfilter();
$post=$request->getPost();
$form->setInputFilter($formValidator->getInputFilter());
$form->setData($request->getPost());
if($form->isValid())
{
$formValidator->exchangeArray($form->getData());
$dbAdapter = $this->serviceLocator->get('Zend\Db\Adapter\Adapter');
$authAdapter = new DbTable($dbAdapter,'Login','username','pwd');
$authAdapter->setIdentity($formValidator->username)
->setCredential($formValidator->pwd);
//->setCredentialTreatment('MD5(?)');
$authService = $this->serviceLocator->get('auth_service');
$authService->setAdapter($authAdapter);
$result = $authService->authenticate();
if($result->isValid())
{
echo 'valid';
exit();
}
else { echo 'invalid';exit();}
}
}
return array('form'=> $form);
我的 module.php 包含
public function getServiceConfig()
{
return array(
'factories' => array(
'auth_service' => function ($sm) {
$authService = new AuthenticationService(new SessionStorage('auth'));
return $authService;
},
'General\Model\Login' => function($sm) {
$tableGateway = $sm->get('LoginGateway');
$table = new Login($tableGateway);
return $table;
},
'LoginGateway' => function ($sm) {
$dbAdapter = $sm->get('Zend\Db\Adapter\Adapter');
$resultSetPrototype = new ResultSet();
$resultSetPrototype->setArrayObjectPrototype(new rotaryfilter());
return new TableGateway('Login', $dbAdapter, null, $resultSetPrototype);
},
),);
}