Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ZendFramewok]Pobranie dodatkowej zmiennej z Zend_Auth_Adaptrer_DbTable
johnyMajster
post
Post #1





Grupa: Zarejestrowani
Postów: 151
Pomógł: 2
Dołączył: 2.08.2012
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


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

Ten post edytował johnyMajster 4.08.2012, 14:42:25
Go to the top of the page
+Quote Post
irmidjusz
post
Post #2





Grupa: Zarejestrowani
Postów: 279
Pomógł: 60
Dołączył: 25.02.2012

Ostrzeżenie: (0%)
-----


Wszystko jest pięknie opisane w manualu: http://framework.zend.com/manual/1.11/en/z...er.dbtable.html
Go to the top of the page
+Quote Post
johnyMajster
post
Post #3





Grupa: Zarejestrowani
Postów: 151
Pomógł: 2
Dołączył: 2.08.2012
Skąd: Wrocław

Ostrzeżenie: (0%)
-----


Akurat tego nigdzie nie widzę (IMG:style_emoticons/default/smile.gif) Ja potrzebuje coś w rodzaju $this->identity w widoku tylko zeby zwracało id (IMG:style_emoticons/default/tongue.gif)
Go to the top of the page
+Quote Post
zend
post
Post #4





Grupa: Zarejestrowani
Postów: 580
Pomógł: 85
Dołączył: 25.03.2010
Skąd: Skrzyszów :)

Ostrzeżenie: (0%)
-----


Przykładowy kod, mam nadzieję że o to Ci chodziło (IMG:style_emoticons/default/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.  
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 19:02