【问题标题】:Zend: no database addapter present errorZend:没有数据库适配器存在错误
【发布时间】: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


    【解决方案1】:

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

    $dbAdapter = Zend_Db::factory ( 'PDO_MYSQL', $objDbConfig);
    AbstractTable::setDefaultAdapter ( $dbAdapter );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-29
      • 1970-01-01
      • 2012-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-09
      相关资源
      最近更新 更多