Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Symfony][Symfony2] czy mogę w klasie Entity reprezentującej tabele wykonać zapytanie?
wiewiorek
post
Post #1





Grupa: Zarejestrowani
Postów: 247
Pomógł: 11
Dołączył: 5.09.2009

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


Mam klasę KategorieEntity i ZdjeciaEntity. W widoku w pętli wyświetlam wszystkie kategorie, jednak chciałbym wywołać moją metodę pobierzNazweMiniaturyKategorii() z KategorieEntity na obiekcie reprezentującym pojedynczą kategorię, tzn. w widoku mam:

  1. <?php foreach ($kategorie as $kategoria): ?>
  2. <?php echo $kategoria->getNazwa() ?>
  3. <img src="<?php echo $view['assets']->getUrl('uploads/'.$kategoria->pobierzNazweMiniaturyKategorii($kategoria->getId())) ?>" />
  4. <?php endforeach; ?>


W klasie KategorieEntity:
  1. class KategorieEntity
  2. {
  3. protected $id;
  4.  
  5. protected $nazwa;
  6.  
  7. //moja metoda:
  8. public function pobierzNazweMiniaturyKategorii($idKategorii)
  9. {
  10. $zdjecie = $this->getEntityManager()
  11. ->createQuery('SELECT z FROM AcmeStronaBundle:ZdjeciaEntity z
  12. JOIN z.kategoria k
  13. WHERE k.id = :idKategorii AND z.glowneKategorii = true')
  14. ->setParameter('idKategorii', $idKategorii)
  15. ->getSingleResult();
  16.  
  17. return $zdjecie->getNazwaMiniatury();
  18. }
  19.  
  20.  
  21. ................
  22. }


Niestety wykonanie zapytania w klasie Entity i wywołanie metody z tej klasy w widoku chyba nie jest mozliwe, bo to nie działa (nie jest też wyświetlany komunikat błedu), więc jak to zrobić?

Ten post edytował wiewiorek 21.03.2012, 14:23:21
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
wiewiorek
post
Post #2





Grupa: Zarejestrowani
Postów: 247
Pomógł: 11
Dołączył: 5.09.2009

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


No nic istotnego własnie nie mówią:

[2012-03-21 14:53:44] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\HttpKernel\EventListener\ProfilerListener::onKernelRequest". [] []
[2012-03-21 14:53:44] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\RouterListener::onEarlyKernelRequest". [] []
[2012-03-21 14:53:44] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\SessionListener::onKernelRequest". [] []
[2012-03-21 14:53:44] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Component\Security\Http\Firewall::onKernelRequest". [] []
[2012-03-21 14:53:44] security.DEBUG: Read SecurityContext from the session [] []
[2012-03-21 14:53:44] security.DEBUG: Reloading user from user provider. [] []
[2012-03-21 14:53:44] doctrine.DEBUG: SET NAMES UTF8 ([]) [] []
[2012-03-21 14:53:44] doctrine.DEBUG: SELECT t0.user_id AS user_id1, t0.username AS username2, t0.email AS email3, t0.password AS password4, t0.salt AS salt5 FROM user t0 WHERE t0.user_id = ? ([1]) [] []
[2012-03-21 14:53:44] security.DEBUG: Username "admin" was reloaded from user provider. [] []
[2012-03-21 14:53:44] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\FrameworkBundle\EventListener\RouterListener::onKernelRequest". [] []
[2012-03-21 14:53:44] request.INFO: Matched route "kategorie_zarzadzanie" (parameters: "_controller": "Acme\StronaBundle\Controller\KategorieController::indexAction", "_route": "kategorie_zarzadzanie") [] []
[2012-03-21 14:53:44] event.DEBUG: Notified event "kernel.request" to listener "Symfony\Bundle\AsseticBundle\EventListener\RequestListener::onKernelRequest". [] []
[2012-03-21 14:53:44] event.DEBUG: Notified event "kernel.controller" to listener "Symfony\Bundle\FrameworkBundle\DataCollector\RequestDataCollector::onKernelController". [] []
[2012-03-21 14:53:44] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ControllerListener::onKernelController". [] []
[2012-03-21 14:53:44] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\ParamConverterListener::onKernelController". [] []
[2012-03-21 14:53:44] event.DEBUG: Notified event "kernel.controller" to listener "Sensio\Bundle\FrameworkExtraBundle\EventListener\TemplateListener::onKernelController". [] []
[2012-03-21 14:53:44] event.DEBUG: Notified event "kernel.controller" to listener "Acme\DemoBundle\ControllerListener::onKernelController". [] []
[2012-03-21 14:53:44] event.DEBUG: Notified event "kernel.controller" to listener "JMS\SecurityExtraBundle\Controller\ControllerListener::onCoreController". [] []
[2012-03-21 14:53:44] doctrine.DEBUG: SELECT k0_.id AS id0, k0_.nazwa AS nazwa1, k0_.opis AS opis2, k0_.data_dodania AS data_dodania3, k0_.data_modyfikacji AS data_modyfikacji4 FROM kategorie k0_ ORDER BY k0_.data_dodania DESC ([]) [] []
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: 16.10.2025 - 06:44