【发布时间】:2014-12-22 06:21:28
【问题描述】:
我正在按照教程制作登录表单。如果用户通过身份验证,只需将用户重定向到主页。如果登录失败,则显示错误。我有错误
No database adapter present
Stack trace:
#0 \Zend_Include\library\Zend\Auth\Adapter\DbTable.php(139): Zend_Auth_Adapter_DbTable->_setDbAdapter(NULL)
#1 \application\controllers\AccountController.php(24): Zend_Auth_Adapter_DbTable->__construct(NULL)
我重读了教程,但代码相同,我不知道为什么会出现此错误。
帐户控制器中的我的 loginAction()
$form = new Application_Model_FormLogin(array('action'=>'/account/login'));
// if the form is submitted
if ($this->getRequest()->isPost()){
if ($form->isValid($this->_request->getPost())) {
$db = Zend_Db_Table::getDefaultAdapter();
$authAdapter = new Zend_Auth_Adapter_DbTable($db);
$authAdapter->setTableName('accounts');
$authAdapter->setIdentityColumn('email');
$authAdapter->setCredentialColumn('pswd');
$authAdapter->setCredentialTreament('MD5(?) and confirmed=1');
$authAdapter->setIdentity($form->getValue('email'));
$authAdapter->setCredential($form->getValue('pswd'));
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
// did the user successfully login
$account = new Application_Model_Account();
$lastLogin = $account->findByEmail($form->getValue('email'));
$lastLogin->last_login = date('Y-m-d H:i:s');
$lastLogin->save();
$this->_helper->flashMessenger->addMessage('You are logged in');
$this->redirector('Index', 'index');
}else{
. . .
}
}else{
. . .
}
$this->view->form = $form;
}
【问题讨论】:
标签: php zend-framework