admin管理员组文章数量:1124808
So, I'm completely at loss about something in my code that don't work and I don't know what and why. Here's the problem :
I'm retrieving results from the database to show what's in store. I have two parts : public, and management. The problem is that I don't have the same results even though the code is almost identical :
Repository :
public function findAllLimit(int $page, $onglet, $filtre = "", array $auts = [], int $limit = 25):array
{
$tirage = ['tirage', 'tirages-anciens'];
$objets = ['objet', 'jeu', 'figurine'];
$result = []; $listId = [];
$query = $this->createQueryBuilder('p')
->leftJoin('p.auteurs', 'a')
->leftJoin('p.dessinateurs', 'd')
->innerJoin('p.editeur', 'e')
->innerJoin('p.serie', 's')
->innerJoin('p.paratype', 't')
->andWhere('p.active = :etat')
->setParameter('etat', true);
if($filtre != ""){
$query->andWhere('p.parabd_titre LIKE :f OR a.nom LIKE :f OR a.prenom LIKE :f OR d.nom LIKE :f OR d.prenom LIKE :f OR e.nom LIKE :f')
->setParameter('f', "%".$filtre."%");
}
if($onglet == 'tintin'){
$query->andWhere("s.nom = 'tintin'");
} elseif($onglet == 'affiche'){
$query->andWhere("s.nom != 'tintin'")
->andWhere("t.nom = 'affiche' ");
} elseif($onglet == 'tirages'){
$query->andWhere("s.nom != 'tintin'")
->andWhere("t.nom IN (:tirage) ")
->setParameter('tirage', $tirage);
} elseif($onglet == 'objets'){
$query->andWhere("s.nom != 'tintin'")
->andWhere("t.nom IN (:objet) ")
->setParameter('objet', $objets);
} elseif($onglet != '') {
$query->andWhere("s.nom != 'tintin'")
->andWhere('t.nom = :type ')
->setParameter('type', $onglet);
}
if(count($auts) > 0) {
foreach($auts as $a) { array_push($listId, $a->getId()); }
$query->andWhere('a.id IN (:ids) OR d.id IN (:ids)')
->setParameter('ids', $listId);
}
$query->orderBy('p.position', 'ASC')
->setMaxResults($limit)
->setFirstResult($page * $limit - $limit);
$paginator = new Paginator($query);
// dd($paginator->getQuery()->getSQL());
$data = $paginator->getQuery()->getResult();
// dd($paginator->count());
if(empty($data)) { //retourne tableau vide pour éviter les erreurs 500
$result['data'] = [];
$result['pages'] = 0;
return $result;
}
//Calcul nb de pages
$pages = ceil($paginator->count() / $limit);
$result['data'] = $data;
$result['pages'] = $pages;
$result['page'] = $page;
$result['limit'] = $limit;
return $result;
}
In the page :
{% block body %}
<h1>Ex-Libris</h1>
{% set path = 'lib_xl' %}
{% set pages = liste.pages %}
{% set currentPage = liste.page %}
{% set haveFilter = true %}
{% set filtre = nomFilt %}
{% set btnList = true %}
{% include "_partials/_pagination.html.twig" %}
<div class="xlAlbum">
{% set n = 0 %}
{% for l in liste.data %}
{% set n = n+1 %}
<div class="xlCard">
<p class="statutXl"><span style="color:{{ l.etatLibris.color }}"> {{ l.etatLibris.libelle|upper }} </span></p>
<p><b>{{ l.livre }} </b><br /><br />{% set i = 0 %}{% set n = l.dessinateurs|length + l.auteurs|length %} {% for a in l.dessinateurs %}{% set i = i+1 %} {{ a.prenom }} {{a.nom}}{% if i > n-1 %} {% elseif i == n - 1 %} et {% else %}, {% endif %} {% endfor %}
{% for a in l.auteurs %}{% set i = i+1 %} {{ a.prenom }} {{a.nom}}{% if i > n-1 %} {% elseif i == n - 1 %} et {% else %}, {% endif %} {% endfor %}</p>
<div class="infoLibris"><img src="{{ asset('/image/xl/') }}{{ l.image }}" class="cursor" />
<div><p>paru aux éditions {{ l.editeur.nom }}<br /> en {{ l.date|format_datetime(pattern='MMMM yyyy', locale='fr') }}</p><br />
<p class="pComm">{{ lmentaire }} </p></div>
</div>
<div id="bdLink{{n}}" class="bdLink">
<ul>{% for bd in l.bdconcernes %}
<li><a href="{{ bd.lien }}" target="_blank">{{ bd.nombd }}</a></li>
{% endfor %}
</ul>
</div>
</div>
{% endfor %}
</div>
{% include "_partials/_pagination.html.twig" %}
For the management part, the code is almost identical as I said (the public one have just one line that block all inactive object (p.active) (none are desactivate, so we can ignore that) and the order is different (by positioning number, but all are at 0, so...)).
The thing is : I have 18 objets that should be showing (SQL and Paginator give 18 objects), but only 14 are up. Why ?
Edit : The problem is fixed adding ->select('DISTINCT p') after the '$this->createQueryBuilder('p')'. Thanks to Julian Koster !
本文标签:
版权声明:本文标题:symfony - Can't get the good number of results with Doctrine and paginator - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736602322a1945244.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论