添加数据到分页器(KnpPaginatorBundle,Symfony)
Add data to paginator (KnpPaginatorBundle, Symfony)
我正在使用 KnpPaginatorBundle。
假设我有这样的东西:
$em = $this->getDoctrine()->getEntityManager();
$qb = $em->createQueryBuilder()
->select('p.id, p.name, p.description)
->from('My\Bundle\Entity\Post', 'p')
->where('p.unread is NULL')
$query = $qb->getQuery();
$posts = $query->getResult();
还有我的分页器:
$paginator = $this->get('knp_paginator');
$posts = $paginator->paginate(
$posts,
$request->query->getInt('page', 1),
3
);
Everythink 工作得很好,但是 我想通过 foreach 将我自己的数据添加到 $posts。
我的示例不起作用:
foreach ($posts as $key => $value) {
$posts [$key]['filterPath'] = 'example';
}
我收到错误 Notice: Indirect modification of overloaded element of Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination has no effect
我该如何解决?
此致
尝试类似的东西
foreach ($posts as $key => $value) {
$tab=$posts[$key];
$tab=['filterPath'] = 'example';
$posts['key']=$tab;
}
据我所知 $posts 不是普通数组,不能直接访问它
我正在使用 KnpPaginatorBundle。
假设我有这样的东西:
$em = $this->getDoctrine()->getEntityManager();
$qb = $em->createQueryBuilder()
->select('p.id, p.name, p.description)
->from('My\Bundle\Entity\Post', 'p')
->where('p.unread is NULL')
$query = $qb->getQuery();
$posts = $query->getResult();
还有我的分页器:
$paginator = $this->get('knp_paginator');
$posts = $paginator->paginate(
$posts,
$request->query->getInt('page', 1),
3
);
Everythink 工作得很好,但是 我想通过 foreach 将我自己的数据添加到 $posts。
我的示例不起作用:
foreach ($posts as $key => $value) {
$posts [$key]['filterPath'] = 'example';
}
我收到错误 Notice: Indirect modification of overloaded element of Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination has no effect
我该如何解决? 此致
尝试类似的东西
foreach ($posts as $key => $value) {
$tab=$posts[$key];
$tab=['filterPath'] = 'example';
$posts['key']=$tab;
}
据我所知 $posts 不是普通数组,不能直接访问它