silverwind
12.01.2016, 03:21:52
Moje Encje [User] one to many [Owner] one to many [Property] one to many [Tenant].
Połączyłem je w repozytorium User
public function getQueryBuilder($User ){
$qb = $this->createQueryBuilder('u')
->select('u,o,p,t')
->Join('u.owner','o')
->Join('o.property','p')
->Join('p.tenant','t')
->where('u.username = :user')
->setParameter('user', $User)
->getQuery()
->getArrayrResult();
return $qb;
}
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
12.01.2016, 06:49:59
Pokaż jeszcze kod encji, wtedy będzie łatwiej. W encji inicjalizujesz DoctrineCollection dla owner?
prz3kus
12.01.2016, 08:07:57
public function getQueryBuilder($User ){
$qb = $this->createQueryBuilder('u')
->select('u,o,p,t')
->Join('u.owner','o')
->Join('o.property','p')
->Join('p.tenant','t')
->where('o.username = :user')//zamiast u -> o 






? ->setParameter('user', $User)
->getQuery()
->getArrayrResult();
return $qb;
}
Forti
12.01.2016, 10:37:37
Nie rozumiem cie co jest źle niby? Wszystko jest ok..
Robisz join i dostajesz te join, więc..?
silverwind
12.01.2016, 15:23:08
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
12.01.2016, 15:25:14
No to zamiast JOIN rob LEFT JOIN
silverwind
12.01.2016, 18:08:51
Teraz mam problem z wyświetleniem tego poprzez pętle for in w Twigu przy Owner mam rozgałęzienie i powstaje tablica druga.
nospor
12.01.2016, 18:12:10
Pokaz jak teraz wyglada zwrocona tablica bo za bardzo nie wiem o jakim rozgalezieniu mowisz.
silverwind
12.01.2016, 18:33:16
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
12.01.2016, 18:35:53
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
13.01.2016, 08:49:51
to jest kontroler
/**
* Lists all Property entities.
*
* @Route("/", name="property_index")
* @Method("GET")
*/
public function indexAction()
{
$User=$this->getUser()->getUsername();
$em = $this->getDoctrine()->getManager();
$AllJoinTableRepo = $em->getRepository('UserUserBundle:User');
$QueryBuilder= $AllJoinTableRepo->getQueryBuilder($User);
'QueryBuilder' => $QueryBuilder,
);
}
petla w szablonie
{% for details in QueryBuilder %}
<th>{{ details.owner.name }}
</th> <th>{{ details.owner.property.name }}
</th> <th>{{ details.owner.property.adress }}
</th>
<th>{{ details.owner.property.tenant.name }}
</th>#}
{% endfor %}
nospor
13.01.2016, 09:57:38
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
13.01.2016, 13:38:16
Przyznam się Naspor że nawet też na to wpadłem

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
13.01.2016, 13:40:06
Zdarza sie kazdemu

Co do schematu, to przygotuj prosze bardziej 'nienaszybko' wersje bo nie kumam jak to ma wygladac ostatecznie
silverwind
13.01.2016, 13:52:14
nospor
13.01.2016, 13:54:23
ok, pokaz teraz kod jaki aktualnie masz
silverwind
13.01.2016, 14:13:42
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
14.01.2016, 11:00:14
Da sie. Ale widze juz skasowales kod co miales i nie jestem w stanie ci teraz dopisac poprawki.
silverwind
14.01.2016, 14:50:02
{% for details in QueryBuilder %}
{% for detailsowner in details.owner %}
<th>{{detailsowner.name}}
</th>
{% endfor %}
{% endfor %}
{% for details in QueryBuilder %}
{% for detailsowner in details.owner %}
{% for detailsproperty in detailsowner.property%}
<th>{{detailsproperty.name}}
</th> <th>{{detailsproperty.adress}}
</th> {% endfor %}
{% endfor %}
{% endfor %}
nospor
14.01.2016, 16:31:26
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
16.01.2016, 21:55:05
To jest kod może komuś będzie pomocny.
{% for details in QueryBuilder %}
{% for detailsowner in details.owner %}
<td>{{detailsowner.name}}
</td> {% for detailsproperty in detailsowner.property%}
{% if loop.length>=2 %}
{% endif %}
<td>{{detailsproperty.name}}
</td> <td>{{detailsproperty.adress}}
</td> {% endfor %}
{% endfor %}
{% endfor %}
chciałem teraz ustawić pustą kolumnę jak wartość np detailsproperty.name jest pusta niestety nie działa mi to
{% for details in QueryBuilder %}
{% for detailsowner in details.owner %}
<th class="text-center">{{loop.index}}
</th> <th class="text-center">{{detailsowner.name}}
</th> {% for detailsproperty in detailsowner.property%}
{% if loop.length>=2 %}
<th class="text-center"></th>
{% endif %}
{% if detailsproperty.name is empty %}// tu jest ten fragment kodu
<th class="text-center"></th> {% endif %}
<th class="text-center">{{detailsproperty.name}}
</th> <th class="text-center">{{detailsproperty.adress}}
</th> <th class="text-center">Najemca
</th> <th class="text-center">saldo
</th>
<a href="{{ path('property_show', { 'id': detailsowner.id }) }}" role="button" class="btn btn-sm btn-primary">zobacz
</a> <a href="{{ path('property_edit', { 'id': detailsowner.id }) }}" role="button" class="btn btn-sm btn-primary">edycja
</a>
{% endfor %}
{% endfor %}
{% endfor %}
nospor
17.01.2016, 13:14:24
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
17.01.2016, 13:29:29
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.