Zend:没有数据库addapter存在错误

时间:2014-12-22 06:21:28

标签: php zend-framework

我正在按照教程制作登录表单。如果用户已通过身份验证,只需将用户重定向到主页即可。如果登录失败,请显示错误。我有错误

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;
    }

1 个答案:

答案 0 :(得分:0)

在使用Zend_Db_Table之前,请尝试以下操作:

$dbAdapter = Zend_Db::factory ( 'PDO_MYSQL', $objDbConfig);
AbstractTable::setDefaultAdapter ( $dbAdapter );
相关问题