Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [doctrine][Symfony2] Jak wyświetlić dane w szablonie
Forum PHP.pl > Forum > PHP > Frameworki
silverwind
Moje Encje [User] one to many [Owner] one to many [Property] one to many [Tenant].

Połączyłem je w repozytorium User

  1. public function getQueryBuilder($User ){
  2. $qb = $this->createQueryBuilder('u')
  3. ->select('u,o,p,t')
  4. ->Join('u.owner','o')
  5. ->Join('o.property','p')
  6. ->Join('p.tenant','t')
  7. ->where('u.username = :user')
  8. ->setParameter('user', $User)
  9. ->getQuery()
  10. ->getArrayrResult();
  11.  
  12. return $qb;
  13. }


Chce wyświetlić je w szablonie.
Problem jest taki że nie wyświetlają mi się wszyscy właściciele użytkownika poniżej jest screen z dumpa.
http://zapodaj.net/7d28ba489cd03.gif.html



Riggs
Pokaż jeszcze kod encji, wtedy będzie łatwiej. W encji inicjalizujesz DoctrineCollection dla owner?
prz3kus
  1. public function getQueryBuilder($User ){
  2. $qb = $this->createQueryBuilder('u')
  3. ->select('u,o,p,t')
  4. ->Join('u.owner','o')
  5. ->Join('o.property','p')
  6. ->Join('p.tenant','t')
  7. ->where('o.username = :user')//zamiast u -> o questionmark.gifquestionmark.gifquestionmark.gifquestionmark.gifquestionmark.gifquestionmark.gifquestionmark.gifquestionmark.gif?
  8. ->setParameter('user', $User)
  9. ->getQuery()
  10. ->getArrayrResult();
  11.  
  12. return $qb;
  13. }
Forti
Nie rozumiem cie co jest źle niby? Wszystko jest ok..

Robisz join i dostajesz te join, więc..?
silverwind
Chyba nie dość jasno wyraziłem się patrzyliście może na screnaa. Chce to wyświetlić sobie w tabelce np Owner Propsety Tenant jak zrobię zapytanie z tymi trzema encjami to nie pokarzemi Owner który nie ma Properyty tylko tych którzy ją mają . Jak ten problem rozwiązać?
nospor
No to zamiast JOIN rob LEFT JOIN
silverwind
Teraz mam problem z wyświetleniem tego poprzez pętle for in w Twigu przy Owner mam rozgałęzienie i powstaje tablica druga.
nospor
Pokaz jak teraz wyglada zwrocona tablica bo za bardzo nie wiem o jakim rozgalezieniu mowisz.
silverwind
tu jest link ze screenem . próbowałem normalnie for in ale wyskakuje mi błąd . Dane wyświetlić chce w tabeli np. Nazwa nieruchomości , adres, właściciel , najemca

[kasuje link bo masz tam hasla....]
nospor
nom, nie ma zadnego rozgalezienia. Owner wyglada dokladnie tak jak wczesniej, tylko ze zamiast tablicy z jednym ownerem masz tablice z dwoma. Rownie dobrze tam moze byc 10 ownerow i to nie powinno miec zadnego wplywu na twoja petle. jesli ma, znaczy ze zrobiles ja zle. Wypadaloby wiec teraz podac kod jaki masz.
silverwind
to jest kontroler
  1. /**
  2.   * Lists all Property entities.
  3.   *
  4.   * @Route("/", name="property_index")
  5.   * @Method("GET")
  6.   */
  7. public function indexAction()
  8. {
  9. $User=$this->getUser()->getUsername();
  10.  
  11. $em = $this->getDoctrine()->getManager();
  12.  
  13. $AllJoinTableRepo = $em->getRepository('UserUserBundle:User');
  14.  
  15. $QueryBuilder= $AllJoinTableRepo->getQueryBuilder($User);
  16.  
  17.  
  18. return array(
  19. 'QueryBuilder' => $QueryBuilder,
  20.  
  21.  
  22. );
  23. }

petla w szablonie
  1. {% for details in QueryBuilder %}
  2. <tr>
  3.  
  4. <th>{{ details.owner.name }}</th>
  5. <th>{{ details.owner.property.name }}</th>
  6. <th>{{ details.owner.property.adress }}</th>
  7.  
  8. <th>{{ details.owner.property.tenant.name }}</th>#}
  9. <th></th>
  10. {% endfor %}


nospor
Nigdzie nie widze petli po owner, petli po property ani petli po tenant. Przeciez kazda z tych rzeczy moze wystapic wielokrotnie i kazda z tych rzeczy jest tablica.
silverwind
Przyznam się Naspor że nawet też na to wpadłem wink.gif hehe. Czasami mi się zdarza pomyśleć. Tylko pojawił się kolejny problem jak to po układać w tabeli? Jak jadę po owner to mi poziomo wyświetla kolumny.
to jest schemat jak by to miało wyglądać tak na szybko

owner property tenat
==========tenat
====property
owner properyt tenat
nospor
Zdarza sie kazdemu smile.gif

Co do schematu, to przygotuj prosze bardziej 'nienaszybko' wersje bo nie kumam jak to ma wygladac ostatecznie sad.gif
silverwind
mniej więcej tak http://naforum.zapodaj.net/7fc66ba36d18.gif.html
nospor
ok, pokaz teraz kod jaki aktualnie masz
silverwind
a da się to w ogóle w takie formie wyświetlić jak chce? Czy może w kontrolerze lub w repozytorium użyć jakieś innej funkcji?
nospor
Da sie. Ale widze juz skasowales kod co miales i nie jestem w stanie ci teraz dopisac poprawki.
silverwind
  1. <tr>
  2. <th>Właściciel</th>
  3. <th>Rodzaj</th>
  4. <th>Adress</th>
  5. <th>Najemca</th>
  6. <th>Saldo</th>
  7. <th>Akcja</th>
  8. </tr>
  9. </thead>
  10. <tr>
  11. {% for details in QueryBuilder %}
  12. {% for detailsowner in details.owner %}
  13. <th>{{detailsowner.name}}</th>
  14.  
  15. {% endfor %}
  16. {% endfor %}
  17. {% for details in QueryBuilder %}
  18. {% for detailsowner in details.owner %}
  19. {% for detailsproperty in detailsowner.property%}
  20. <th>{{detailsproperty.name}}</th>
  21. <th>{{detailsproperty.adress}}</th>
  22. {% endfor %}
  23. {% endfor %}
  24. {% endfor %}
nospor
Chce ci tylko pokazac schemat jak to sie mniej wiecej robi
Wybacz za pseudoif w kodzie, ale nie pamietam juz skladni ifow w szablonach
Kod
                   {% for details in QueryBuilder %}    
                       {% for detailsowner in details.owner %}
<tr>
                           <td>{{detailsowner.name}}</td>
                           {% for detailsproperty in detailsowner.property%}
                            {JESLI to jest kolejny (to jest drugi lub dalszy) element w detailsowner.property}
                               </tr>
                               <tr>
                                   <td>Puste pole na WLASCICIELA</td>
                             {KONIEC JESLI}
                           <td>{{detailsproperty.name}}</td>
                           <td>{{detailsproperty.adress}}</td>
                        {% endfor %}
</tr>
                       {% endfor %}
                   {% endfor %}

Mniej wiecej cos w ten desen
silverwind
To jest kod może komuś będzie pomocny.
  1. {% for details in QueryBuilder %}
  2. {% for detailsowner in details.owner %}
  3. <tr>
  4. <td>{{loop.index}}</td>
  5. <td>{{detailsowner.name}}</td>
  6. {% for detailsproperty in detailsowner.property%}
  7. {% if loop.length>=2 %}
  8. </tr>
  9. <tr>
  10. <td> </td>
  11. {% endif %}
  12. <td>{{detailsproperty.name}}</td>
  13. <td>{{detailsproperty.adress}}</td>
  14. {% endfor %}
  15. </tr>
  16. {% endfor %}
  17. {% endfor %}


chciałem teraz ustawić pustą kolumnę jak wartość np detailsproperty.name jest pusta niestety nie działa mi to

  1. {% for details in QueryBuilder %}
  2. {% for detailsowner in details.owner %}
  3. <tr>
  4. <th class="text-center">{{loop.index}}</th>
  5. <th class="text-center">{{detailsowner.name}}</th>
  6. {% for detailsproperty in detailsowner.property%}
  7.  
  8.  
  9. {% if loop.length>=2 %}
  10. </tr>
  11. <tr>
  12. <th class="text-center"></th>
  13.  
  14.  
  15. {% endif %}
  16.  
  17. {% if detailsproperty.name is empty %}// tu jest ten fragment kodu
  18. <th class="text-center"></th>
  19. {% endif %}
  20. <th class="text-center">{{detailsproperty.name}}</th>
  21. <th class="text-center">{{detailsproperty.adress}}</th>
  22. <th class="text-center">Najemca</th>
  23. <th class="text-center">saldo</th>
  24. <th class="text-center">
  25.  
  26. <a href="{{ path('property_show', { 'id': detailsowner.id }) }}" role="button" class="btn btn-sm btn-primary">zobacz</a>
  27. <a href="{{ path('property_edit', { 'id': detailsowner.id }) }}" role="button" class="btn btn-sm btn-primary">edycja</a>
  28.  
  29. </th>
  30.  
  31. {% endfor %}
  32. </tr>
  33.  
  34.  
  35.  
  36. {% endfor %}
  37. {% endfor %}

nospor
1) Co to znaczy ze ci to nie dziala??
2) Poza tym nie kumam twojej logiki.... Jak wartosc jest, to tworzysz jedna TH na te wartosc. Gdy Wartosci nie ma, to chcesz tworzysz jedno puste TH oraz nadal TH z pusta wartoscia - czyli dla pustej wartosci teraz tworzysz dwie TH przez co rozwalasz totalnie strukture tabeli
silverwind
Chodziło mi żeby wstawić kolumny jak nie ma wartości, ale udało mi się już to zrobic
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.