Frgament kodu:
Kod
$user = new Admin;
$auth = Zend_Auth::getInstance();
$authAdapter = new Zend_Auth_Adapter_DbTable(
$user -> getAdapter(),
'admin',
'login',
'pass'
);
$authAdapter -> setIdentity('admin') ->setCredential('haslo');
$result = $auth -> authenticate($authAdapter);
switch($result->getCode()) //dalej costam, nieistotne
$auth = Zend_Auth::getInstance();
$authAdapter = new Zend_Auth_Adapter_DbTable(
$user -> getAdapter(),
'admin',
'login',
'pass'
);
$authAdapter -> setIdentity('admin') ->setCredential('haslo');
$result = $auth -> authenticate($authAdapter);
switch($result->getCode()) //dalej costam, nieistotne
Powyzszy kod dziala bez zadnego problemu. Zastanawia jednak jego uzytecznosc - po co robic cos, co i tak ma statycznie zapisane w sobie login i haslo? No to do dziela, formularz, jedna zmiana w kodzie:
Kod
$authAdapter -> setIdentity($admin) ->setCredential($haslo);
i otrzymuje, zamiast komunikatu o logowaniu (badz nie):
Cytat
Wystapil nastepujacy blad:
exception 'Zend_Auth_Adapter_Exception' with message 'A credential value was not provided prior to authentication with Zend_Auth_Adapter_DbTable.' in C:\WebServ\httpd-users\bash\library\Zend\Auth\Adapter\DbTable.php:324 Stack trace: #0 C:\WebServ\httpd-users\bash\library\Zend\Auth\Adapter\DbTable.php(284): Zend_Auth_Adapter_DbTable->_authenticateSetup() #1 C:\WebServ\httpd-users\bash\library\Zend\Auth.php(117): Zend_Auth_Adapter_DbTable->authenticate() #2 C:\WebServ\httpd-users\bash\application\default\controllers\AdminController.php(90): Zend_Auth->authenticate(Object(Zend_Auth_Adapter_DbTable)) #3 C:\WebServ\httpd-users\bash\library\Zend\Controller\Action.php(494): AdminController->indexAction() #4 C:\WebServ\httpd-users\bash\library\Zend\Controller\Dispatcher\Standard.php(285): Zend_Controller_Action->dispatch('indexAction') #5 C:\WebServ\httpd-users\bash\library\Zend\Controller\Front.php(934): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #6 C:\WebServ\httpd-users\bash\application\bootstrap.php(23): Zend_Controller_Front->dispatch() #7 C:\WebServ\httpd-users\bash\public\index.php(8): require('C:\WebServ\http...') #8 {main}
exception 'Zend_Auth_Adapter_Exception' with message 'A credential value was not provided prior to authentication with Zend_Auth_Adapter_DbTable.' in C:\WebServ\httpd-users\bash\library\Zend\Auth\Adapter\DbTable.php:324 Stack trace: #0 C:\WebServ\httpd-users\bash\library\Zend\Auth\Adapter\DbTable.php(284): Zend_Auth_Adapter_DbTable->_authenticateSetup() #1 C:\WebServ\httpd-users\bash\library\Zend\Auth.php(117): Zend_Auth_Adapter_DbTable->authenticate() #2 C:\WebServ\httpd-users\bash\application\default\controllers\AdminController.php(90): Zend_Auth->authenticate(Object(Zend_Auth_Adapter_DbTable)) #3 C:\WebServ\httpd-users\bash\library\Zend\Controller\Action.php(494): AdminController->indexAction() #4 C:\WebServ\httpd-users\bash\library\Zend\Controller\Dispatcher\Standard.php(285): Zend_Controller_Action->dispatch('indexAction') #5 C:\WebServ\httpd-users\bash\library\Zend\Controller\Front.php(934): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http)) #6 C:\WebServ\httpd-users\bash\application\bootstrap.php(23): Zend_Controller_Front->dispatch() #7 C:\WebServ\httpd-users\bash\public\index.php(8): require('C:\WebServ\http...') #8 {main}
Pogooglowalem, znalazlem jeden ciekawy przyklad, ktory jest tak samo bezuzyteczny, jak ten, ktory przedstawilem na samym poczatku.
Rowniez manual przedstawia podobny przyklad - LINK
Co ciekawe - mam na dysku kod zrodlowy pewnego portalu, z ktorego korzystam przy nauce i tam rozwiazanie zaprezentowane ze zmiennymi dziala bez problemu.
Z gory dziekuje za pomoc.
PS: Prosze nie krzyczec, ze nie uzywam zadnego szyfrowania/hashowania hasła, ale doszedlem do wniosku, ze chce miec najbanalniejszy przyklad, ktory dziala, niz wybajerzony, ktory bedzie plul bledami

Edit: rozwiazane. Problemem bylo nieprzekazywanie parametrow z formularza (a raczej sposob, w jaki chcialem je odczytac). Poprawilem to po prostu na metode getPost() i teraz wszystko dziala.