2015-09-26 58 views
3

我正在使用KnpPaginatorBundle。將數據添加到paginator(KnpPaginatorBundle,Symfony)

讓我們說我有這樣的事情:

$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,由

我的例子不工作:

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

我得到錯誤Notice: Indirect modification of overloaded element of Knp\Bundle\PaginatorBundle\Pagination\SlidingPagination has no effect

我該如何解決呢? 問候

回答

2

嘗試類似的東西

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

至於我記得$帖子是不正常的陣列,它不能直接訪問

+0

非常感謝你! :) – Gemmi