Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [ZendFramework][ZendFramework2] Użycie getServiceLocator w modelu
netvalue
post 14.05.2016, 20:34:07
Post #1





Grupa: Zarejestrowani
Postów: 199
Pomógł: 2
Dołączył: 9.06.2008

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


na potrzeby Zend\Authentication\AuthenticationService stworzyłem własny model
kod ponizej, w którym próbuję wywołać

  1. $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');

lecz niestety dostaje odpowiedź że nie ma takiej metody jak getServiceLocator ... w kontrolerze tak się odwołuję i nie mam problemu.... (ten sam moduł)

  1. <?php
  2.  
  3. namespace Login\Model;
  4.  
  5. use Zend\Authentication\Adapter\AdapterInterface;
  6. use Zend\Authentication\Result as AuthResult;
  7.  
  8. class CustomAdapter implements AdapterInterface {
  9.  
  10. protected $customer;
  11. protected $login;
  12. protected $password;
  13. protected $adapter;
  14.  
  15.  
  16.  
  17. public function getAdapter() {
  18. if (!$this->adapter) {
  19.  
  20. $this->adapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter');
  21. }
  22. return $this->adapter;
  23. }
  24.  
  25. /**
  26.   * @return \Zend\Authentication\Result
  27.   */
  28. public function authenticate() {
  29. $this->getAdapter();
  30. /
  31. }
  32.  
  33. public function setCustomer($data) {
  34. $this->customer = $data;
  35. }
  36.  
  37. public function setLogin($data) {
  38. $this->login = $data;
  39. }
  40.  
  41. public function setPassword($data) {
  42. $this->password = md5($data);
  43. }
  44.  
  45. }
  46.  


Ten post edytował netvalue 14.05.2016, 20:39:54
Go to the top of the page
+Quote Post
Szymciosek
post 15.05.2016, 10:10:54
Post #2





Grupa: Zarejestrowani
Postów: 1 168
Pomógł: 126
Dołączył: 5.02.2010
Skąd: Świdnica

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


http://framework.zend.com/manual/current/e...urning-an-array

dokładniej: Creating a ServiceLocator-aware class
Go to the top of the page
+Quote Post
netvalue
post 16.05.2016, 11:11:24
Post #3





Grupa: Zarejestrowani
Postów: 199
Pomógł: 2
Dołączył: 9.06.2008

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


podziękował smile.gif

Ten post edytował netvalue 16.05.2016, 11:32:48
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 28.05.2024 - 02:54