我正在使用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非常有效,但我想将自己的数据添加到$ post 中。
我的例子不起作用:
foreach ($posts as $key => $value) {
$posts [$key]['filterPath'] = 'example';
}
我收到错误Notice: Indirect modification of overloaded element of Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination has no effect
我该如何解决? 此致
答案 0 :(得分:2)
尝试类似的东西
foreach ($posts as $key => $value) {
$tab=$posts[$key];
$tab=['filterPath'] = 'example';
$posts['key']=$tab;
}
据我记得,$ posts不是正常数组,无法直接访问