Zend_Db_Table::getDefaultAdapter nicht funktioniert
Hallo, ich bin mit dem zend framework , in meinem login-controller, index-action . wenn ein Benutzer das senden des Anmeldeformulars , ich werde versuchen, die DefaultAdapter , ich habe versucht, es durch
$db = Zend_Db_Table::getDefaultAdapter();
- und das wird nicht funktionieren .
aber ich
$db = Zend_Db::factory('Pdo_Mysql', array(
'host' => 'localhost',
'username' => 'root',
'password' => '123',
'dbname' => 'test'
));
dann ist es arbeiten .
dies ist meine index-Aktion
public function indexAction() {
$loginform = new Application_Form_LoginForm();
if($this->getRequest()->getPost()) {
$filter = new Zend_Filter_StripTags();
$name = $filter->filter($this->getRequest()->getPost('name'));
$password = $filter->filter($this->getRequest()->getPost('password'));
//$db = Zend_Db_Table::getDefaultAdapter();
$db = Zend_Db::factory('Pdo_Mysql', array(
'host' => 'localhost',
'username' => 'root',
'password' => '123',
'dbname' => 'test'
));
$authAdapter = new Zend_Auth_Adapter_DbTable($db);
$authAdapter->setTableName('users');
$authAdapter->setIdentityColumn('username');
$authAdapter->setCredentialColumn('password');
//Set the input credential values to authenticate against
$authAdapter->setIdentity($name);
$authAdapter->setCredential($password);
//do the authentication
$auth = Zend_Auth::getInstance();
$result = $auth->authenticate($authAdapter);
if ($result->isValid()) {
//success : store database row to auth's storage system except the password column
$data = $authAdapter->getResultRowObject(null, 'password');
$auth->getStorage()->write($data);
$this->_redirect('/index/');
} else {
$this->view->errors = array(0 => array(0 => 'Username and/or password are invalid.'));
$this->view->form = $loginform;
}
}
else {
$this->view->form = $loginform;
}
}
habe ich definiere meine Datenbank connection details in meiner Anwendung.ini wie diese
resources.db.adapter = "PDO_MYSQL"
resources.db.params.host = "localhost"
resources.db.params.username = "root"
resources.db.params.password = "123"
resources.db.params.dbname = "test"
warum meine Zend_Db_Table::getDefaultAdapter();
funktioniert nicht , der Fehler ist
An error occurred
Application error
Exception information:
Message: No database adapter present
Stack trace:
#0 /home/kanishka/workspace/hospital_system/library/Zend/Auth/Adapter/DbTable.php(140): Zend_Auth_Adapter_DbTable->_setDbAdapter(NULL)
#1 /home/kanishka/workspace/hospital_system/application/controllers/LoginController.php(30): Zend_Auth_Adapter_DbTable->__construct(NULL)
#2 /home/kanishka/workspace/hospital_system/library/Zend/Controller/Action.php(513): LoginController->indexAction()
#3 /home/kanishka/workspace/hospital_system/library/Zend/Controller/Dispatcher/Standard.php(295): Zend_Controller_Action->dispatch('indexAction')
#4 /home/kanishka/workspace/hospital_system/library/Zend/Controller/Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#5 /home/kanishka/workspace/hospital_system/library/Zend/Application/Bootstrap/Bootstrap.php(97): Zend_Controller_Front->dispatch()
#6 /home/kanishka/workspace/hospital_system/library/Zend/Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#7 /home/kanishka/workspace/hospital_system/public/index.php(26): Zend_Application->run()
#8 {main}
Request Parameters:
array (
'controller' => 'login',
'action' => 'index',
'module' => 'default',
'name' => '',
'password' => '',
'submit' => 'submit',
)
Haben Sie eine
_initDb
Methode in der Bootstrap?
InformationsquelleAutor Kanishka Panamaldeniya | 2011-07-13
Du musst angemeldet sein, um einen Kommentar abzugeben.
Fügen Sie diese zu Ihrer Konfiguration
es sei denn, Sie überschrieben Db Ressource, Standard-adapter registriert werden.
mm ich denke, dass ich nicht überschreiben, die Db-Ressource ...... 🙁
hinzufügen
var_dump($this->getDbAdapter()); exit;
Recht am Anfang der init () - Methode in Zend_Application_Resource_Db, um es zu überprüfenstellen Sie sicher, dass Sie löschen Sie Ihren cache, wenn überhaupt und es dann probieren. Zend Framework-cache ist es Klassen und
application.ini
könnte auch zwischengespeichert wurden.InformationsquelleAutor Xerkus
Sollten Sie diese Funktion in Bootstrap
InformationsquelleAutor phutc
Versuchen, fügen Sie diese
in der das Ende der Datei PROJECTNAME\public\.htaccess
InformationsquelleAutor MEGApixel23