Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [ZendFramewok]Pobranie dodatkowej zmiennej z Zend_Auth_Adaptrer_DbTable
Forum PHP.pl > Forum > PHP > Frameworki
johnyMajster
Witam serdecznie w akcji logowania tworze pewien adapter:

  1.  
  2. public function loginAction()
  3. {
  4. //$this->_helper->viewRenderer('index');
  5. $form = new Application_Form_Login();
  6. if ($form->isValid($this->getRequest()->getPost())) {
  7.  
  8. $adapter = new Zend_Auth_Adapter_DbTable(
  9. null,
  10. 'user',
  11. 'email',
  12. 'password',
  13. 'MD5(CONCAT(?, salt))'
  14. );
  15. $adapter->setIdentity($form->getValue('email'));
  16. $adapter->setCredential($form->getValue('password'));
  17.  
  18. $auth = Zend_Auth::getInstance();
  19. $result = $auth->authenticate($adapter);
  20.  
  21. if ($result->isValid()) {
  22. if (($form->getValue('rememberme'))==1) {
  23. Zend_Session::rememberMe();
  24. }
  25. else
  26. {
  27. Zend_Session::forgetMe();
  28. }
  29. return $this->_helper->redirector(
  30. 'myprofil',
  31. 'profil',
  32. 'default'
  33. );
  34. }
  35. $form->password->addError('Błędna próba logowania!');
  36. }
  37. $this->view->form = $form;
  38. }


chodzi o $adapter

Czy mogę z niego wyciągnąc id użytkownika ale nie w tej samej akcji? Czy jest ono zapisane na zasadzie sesji czy musze to sam zrobic podczas logowania??

W tej samej akcji to można zrobic tak print_r($adapter->getResultRowObject()); ale ja bym chciał miec możliwosc dostepu z innej akcji
irmidjusz
Wszystko jest pięknie opisane w manualu: http://framework.zend.com/manual/1.11/en/z...er.dbtable.html
johnyMajster
Akurat tego nigdzie nie widzę smile.gif Ja potrzebuje coś w rodzaju $this->identity w widoku tylko zeby zwracało id tongue.gif
zend
Przykładowy kod, mam nadzieję że o to Ci chodziło smile.gif
  1. $password = md5( self::PASSWORD_SALT . $password);
  2. $dbAdapter = $this -> _table -> getAdapter();
  3. $emailQuoted = $dbAdapter -> quoteInto('email = ?', $login);
  4. $passwordQuoted = $dbAdapter -> quoteInto('`password` = ?', $password);
  5.  
  6. $select = $this -> _table -> select()
  7. -> where( '('.$emailQuoted.' AND '.$passwordQuoted . ')')
  8. -> where(' `status` = "accepted" ')
  9. ;
  10.  
  11. $row = $this -> _table -> fetchRow($select);
  12.  
  13. if(!is_object($row))
  14. {
  15. return false;
  16. }
  17.  
  18. $auth = Zend_Auth::getInstance();
  19. $storage = $auth -> getStorage();
  20. $storage -> clear();
  21. $storage -> write(new My_Auth_Result($row -> toArray()));
  22.  
  23. class My_Auth_Result implements Zend_Acl_Role_Interface
  24. {
  25. protected $_data = array();
  26.  
  27. public function __construct($data)
  28. {
  29. $this -> _data = (array)$data;
  30. }
  31.  
  32. public function __set($name , $value)
  33. {
  34. $this -> _data[$name] = $value;
  35. }
  36.  
  37. public function __get($name)
  38. {
  39. return $this -> _data[$name];
  40. }
  41.  
  42. public function __isset($name)
  43. {
  44. return isset($this -> _data[$name]);
  45. }
  46.  
  47. public function getId()
  48. {
  49. return $this -> id;
  50. }
  51. }
  52.  
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.