I'm using KnpPaginatorBundle.
Let say I've got something like this:
$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();
And my paginator:
$paginator = $this->get('knp_paginator');
$posts = $paginator->paginate(
$posts,
$request->query->getInt('page', 1),
3
);
Everythink works very well, but I would like to add my own data to $posts by foreach.
My example don't work:
foreach ($posts as $key => $value) {
$posts [$key]['filterPath'] = 'example';
}
I get error Notice: Indirect modification of overloaded element of Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination has no effect
How can I solve it? Regards
try something like that
foreach ($posts as $key => $value) {
$tab=$posts[$key];
$tab=['filterPath'] = 'example';
$posts['key']=$tab;
}
As far as i remember $posts isn't normal array and it cannot be accessed directly