Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony][SF3] Wywołanie magicznej methody __call
kusiu
post
Post #1





Grupa: Zarejestrowani
Postów: 163
Pomógł: 10
Dołączył: 24.01.2006

Ostrzeżenie: (30%)
XX---


Zaimplementowalem https://github.com/KnpLabs/DoctrineBehaviors#translatable, natomiast methoda __call, ktora umiescilem w entity nie jest wykonywana:

  1. public function __call($method, $arguments)
  2. {
  3. return $this->proxyCurrentLocaleTranslation($method, $arguments);
  4. }


  1. Neither the property "name" nor one of the methods "getName()", "name()", "isName()", "hasName()", "__get()" exist and have public access in class "AppBundle\Entity\Occupation".


Co powinienem zrobic aby methoda __call nie byla ignorowana?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kusiu
post
Post #2





Grupa: Zarejestrowani
Postów: 163
Pomógł: 10
Dołączył: 24.01.2006

Ostrzeżenie: (30%)
XX---


Cytat(nospor @ 12.02.2018, 11:50:13 ) *
czemu __call? Powininies zaimplementowac __get(). Nawet komunikat bledu ci to wyraznie mowi


Spojrz na przyklad w dokumentacji https://github.com/KnpLabs/DoctrineBehaviors#translatable

Magiczna methoda __call przydaje sie gdy chce sie wyciagnac dane przez:

  1. $occupation = $this->getDoctrine()->getEntityManager()->getRepository(Occupation::class)->find(1);
  2. dump($occupation->getName());


Ten blad pojawia sie w przypadku odczytywania danych w formularzu. Czy nie lepiej bylo by nadpisac PropertyAccessor by sprawdzal tez funckcje __call?

Teoretycznie moglbym w entity miec zarowno __call ja i _get, jednak...

  1. public function __get($name)
  2. {
  3. $methodName = "get" . ucfirst($name);
  4. return $this->proxyCurrentLocaleTranslation($methodName, []);
  5. }
  6.  
  7. public function __call($method, $arguments)
  8. {
  9. return $this->proxyCurrentLocaleTranslation($method, $arguments);
  10. }
Go to the top of the page
+Quote Post

Posty w temacie


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: 18.10.2025 - 06:02