Bonsoir !

Bon décidemment j'ai pas mal de problème avec mes queryBuilder et autre. Je m'explique :

Dans mon forum sur ma page nommée forum.html.twig j'aimerai afficher mes topics rangé dans un ordre croissant en fonction de la date de son dernier post.

J'ai donc dans mon controller :

ForumController :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
public function forumAction(Forum $forum, $tagForum)
	{
		$category = $forum->getCategorie();
		// $topics = $forum->getTopics();
 
		$listeTopics = $this->getDoctrine()
					   ->getEntityManager()
					   ->getRepository('SdsForumBundle:Forum')
					   ->findByIdOrderByPostsDateASC($forum->getId());
 
		return $this->render('SdsForumBundle:Forum:forum.html.twig', array('forum' => $forum, 'tagForum' => $tagForum, 'category' => $category, 'listeTopics' => $listeTopics));
	}
Mon ForumRepository :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
public function findByIdOrderByPostsDateASC($id)
	{
		$qb = $this->createQueryBuilder('f')
		->join('f.topics', 't')
		->addSelect('t')
		->join('t.posts', 'p')
		->addSelect('p')
		->where('f.id = :id')
		->setParameter('id', $id)
		->orderBy('p.date', 'ASC');
 
		return $qb->getQuery()
			      ->getResult();
	}
ma page forum.html.twig :

{# src/Sds/ForumBundle/Resources/views/Forum/forum.html.twig #}

{% extends "SdsSiteBundle::layout.html.twig" %}

{% block title %}Forum - {{ parent() }}{% endblock %}

{% block sdssite_body %}

<div id="forum">

<div id="globalforum">
<div id="catforums">

<p>
<a style="color: #bc2a4d;" href="{{ path('SdsForumBundle_accueil') }}">
{{ category.nom|upper }}
</a><span style="font-size: 8px; font-weight: bold;"> << </span>
<a style="color: #bc2a4d;" href="{{ path('SdsForumBundle_forum', { 'id': forum.id, 'tagForum': tagForum }) }}">
{{ tagForum|upper }}
</a>
</p>
<table class="categories">
<thead>
<tr>
<th style="width: 100px;">SUJETS</th>
<th style="width: 100px;">REPONSES</th>
<th style="width: 100px;">VU</th>
<th style="text-align: center; width: 240px;">DERNIER MESSAGE</th>
</tr>
</thead>

{% if listeTopics is defined %}

{% if listeTopics is empty %}

<tbody class="forums">
<tr>
<td>
Aucun topic n'est disponible dans ce forum
</td>
</tr>
</tbody>

{% endif %}

{% for topic in listeTopics %}

<tbody class="forums">
<tr>
<td style="padding-left: 5px;">
<a href="{{ path('SdsForumBundle_topic', { 'id': topic.id, 'tagTopic': topic.titre }) }}">{{ topic.titre }}</a><br />
</td>
<td style="text-align: center;">
<span style="font-size: 10px; font-weight: bold">{{ topic.post }}</span>
</td>
<td style="text-align: center;">
<span style="font-size: 10px; font-weight: bold">{{ topic.vu }}</span>
</td>
<td style="text-align: center;">

{% include "SdsForumBundle:Forum:lastPost.html.twig" with { 'post' : topic.lastPost } %}

</td>
</tr>
</tbody>

{% endfor %}

{% endif %}

</table>

</div>
</div>

</div>

{% endblock %}
Bien sur ça ne fonctionne pas et je passe des heures sans trouver ma réponse.

Merci d'avance.