3

我正在使用 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

我该如何解决?问候

4

1 回答 1

2

尝试类似的东西

foreach ($posts as $key => $value) {
$tab=$posts[$key];
$tab=['filterPath'] = 'example';
$posts['key']=$tab;
}

据我记得 $posts 不是普通数组,不能直接访问

于 2015-09-27T17:51:56.797 回答