在Zend框架中Zend_Db_Table :: getDefaultAdapter()返回Null [英] In Zend Framework Zend_Db_Table::getDefaultAdapter() returns Null

查看:193
本文介绍了在Zend框架中Zend_Db_Table :: getDefaultAdapter()返回Null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想实现一个 getAuthAdapter(array $ form)

 私人函式getAuthAdapter(array $ form){

$ authAdapter = new Zend_Auth_Adapter_DbTable (
Zend_Db_Table :: getDefaultAdapter(),
'user',
'email',
'password',
'MD5(?)AND hidden =FALSE ');
$ authAdapter-> setIdentity($ form ['email'])
- > setCredential($ form ['password']);

return $ authAdapter;
}

要建立数据库连接, .ini

  resources.db.adapter =PDO_MYSQL
resources.db.params.host =localhost
resources.db.params.username = web5
resources.db.params.password = ACv8vSdn
resources.db.params.dbname = usr_web5_1
resourses.db .isDefaultTableAdapter = true

但在尝试脚本后,遇到以下错误:

 应用程序错误
异常信息:

消息:不存在数据库适配器
堆栈跟踪:

0 /usr/share/php/libzend-framework-php/Zend/Auth/Adapter/DbTable.php(140):Zend_Auth_Adapter_DbTable-> _setDbAdapter(NULL)
1 / var / www / web5 / html / application / controllers / LoginController.php(49):Zend_Auth_Adapter_DbTable-> __ construct(NULL,'user','email','password','MD5(?)AND hidd ...')
2 /var/www/web5/html/application/controllers/LoginController.php(23):LoginController-> getAuthAdapter(Array)
3 / usr / share / php / libzend-framework-php / Zend / Controller / Action.php(513):LoginController-> indexAction()
4 /usr/share/php/libzend-framework-php/Zend/Controller/Dispatcher/Standard.php(295):Zend_Controller_Action-> ; dispatch('indexAction')
5 /usr/share/php/libzend-framework-php/Zend/Controller/Front.php(954):Zend_Controller_Dispatcher_Standard-> dispatch(Object(Zend_Controller_Request_Http),Object(Zend_Controller_Response_Http ))
6 /usr/share/php/libzend-framework-php/Zend/Application/Bootstrap/Bootstrap.php(97):Zend_Controller_Front-> dispatch()
7 / usr / share / php / libzend-framework-php / Zend / Application.php(366):Zend_Application_Bootstrap_Bootstrap-> run()
8 /var/www/web5/html/public/index.php(26):Zend_Application-> ; run()
9 {main}

请求参数:

数组(
'controller'=> 'login',
'action'=> 'index',
'module'=> 'default',
'email'=> 'test@domain.com',
'password'=> 'test',
'login'=> '登录',


解决方案

想检查你的引导程序并调试加载数据库的代码。


after serching up and down the internets, finding no proper answer, I am asking you:

I want to implement a getAuthAdapter(array $form)

private function getAuthAdapter(array $form) {  

  $authAdapter = new Zend_Auth_Adapter_DbTable(
     Zend_Db_Table::getDefaultAdapter(),
     'user',
     'email',
     'password',
     'MD5(?) AND hidden = "FALSE"');   
  $authAdapter->setIdentity($form['email'])
     ->setCredential($form['password']);

  return $authAdapter;
}

To establish a database connection, I added following lines to my application.ini

    resources.db.adapter = "PDO_MYSQL"
    resources.db.params.host = "localhost"
    resources.db.params.username = web5
    resources.db.params.password = ACv8vSdn
    resources.db.params.dbname = usr_web5_1
    resourses.db.isDefaultTableAdapter = true

But after trying the script I experience following error:

Application error
Exception information:

Message: No database adapter present
Stack trace:

0 /usr/share/php/libzend-framework-php/Zend/Auth/Adapter/DbTable.php(140):     Zend_Auth_Adapter_DbTable->_setDbAdapter(NULL)
1 /var/www/web5/html/application/controllers/LoginController.php(49): Zend_Auth_Adapter_DbTable->__construct(NULL, 'user', 'email', 'password', 'MD5(?) AND hidd...')
2 /var/www/web5/html/application/controllers/LoginController.php(23): LoginController->getAuthAdapter(Array)
3 /usr/share/php/libzend-framework-php/Zend/Controller/Action.php(513): LoginController->indexAction()
4 /usr/share/php/libzend-framework-php/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('indexAction')
5 /usr/share/php/libzend-framework-php/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
6 /usr/share/php/libzend-framework-php/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
7 /usr/share/php/libzend-framework-php/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
8 /var/www/web5/html/public/index.php(26): Zend_Application->run()
9 {main}  

Request Parameters:

array (
  'controller' => 'login',
  'action' => 'index',
  'module' => 'default',
  'email' => 'test@domain.com',
  'password' => 'test',
  'login' => 'Login',
)  

解决方案

You might want to check you bootstrapper and debug your code which loads the db.

这篇关于在Zend框架中Zend_Db_Table :: getDefaultAdapter()返回Null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆