Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony] odwołanie do Doctrine w niezależnej klasie
dopelganger
post
Post #1





Grupa: Zarejestrowani
Postów: 236
Pomógł: 0
Dołączył: 27.10.2012

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


cześć
mam klasę w której są różne pomocnicze metody, ale za piernika nie wiem w jaki sposób odwołać się do Doctrine,,,
Wywala błąd:/

Attempted to call an undefined method named "getDoctrine" of class "MyBundle\Entity\Helper".

  1. <?php
  2.  
  3. namespace MyBundle\Entity;
  4.  
  5. class Helper {
  6.  
  7. // ....
  8.  
  9. public function Cos() {
  10. return $this->getDoctrine()->getManager()->createQuery("zapytanie")->getResult();
  11. }
  12.  
  13. }


Prosze o pomoc.
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kapslokk
post
Post #2





Grupa: Zarejestrowani
Postów: 965
Pomógł: 285
Dołączył: 19.06.2015
Skąd: Warszawa

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


Skoro wstrzyknąłeś entity manager, to zamień
  1. public function Cos() {
  2. return $this->getDoctrine()->getManager()->createQuery("zapytanie")->getResult();
  3. }

na
  1. public function Cos() {
  2. return $this->em->createQuery("zapytanie")->getResult();
  3. }
Go to the top of the page
+Quote Post
dopelganger
post
Post #3





Grupa: Zarejestrowani
Postów: 236
Pomógł: 0
Dołączył: 27.10.2012

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


Cytat(kapslokk @ 11.03.2016, 08:22:48 ) *
Skoro wstrzyknąłeś entity manager, to zamień
  1. public function Cos() {
  2. return $this->getDoctrine()->getManager()->createQuery("zapytanie")->getResult();
  3. }

na
  1. public function Cos() {
  2. return $this->em->createQuery("zapytanie")->getResult();
  3. }



dziękuje!
Go to the top of the page
+Quote Post

Posty w temacie


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 Aktualny czas: 19.08.2025 - 05:32