2017-11-15 15 views
0

symfony3アプリケーションでmongoDBを使用しています。私のリポジトリにsetMaxResultssetFirstResultを使用してリスティングアクションのページ付けを行う必要があります。しかし、私はデータベースとしてMySqlを使用するのに多く使用されています。私は自分のカスケードでそれを行う方法を見つけません。MongoDB Symfony3ページ分割From QueryBuilderを使用した結果を制限する

私はこのようにそれを使用してみました:

$qb = $this->createQueryBuilder('DemoBundle:Entity'); 
$qb ->select('u'); 
$qb ->setMaxResults($max) 
    ->setFirstResult($first); 

しかし、以下のように、私はエラーを持っている:

は教義\ ODMクラス の「はsetMaxResults」」という名前の未定義のメソッドを呼び出そうとしました\ MongoDBの\クエリー\ビルダー

フル機能があり、このようなとして:

public function search($data, $page = 0, $max = NULL, $getResult = true) 
{ 
    $qb = $this->createQueryBuilder('AresAPITournamentBundle:Tournament'); 
    $query = isset($data['query']) && $data['query']?$data['query']:null; 

    $qb ->select('u'); 

    if ($query) { 
     $qb 
      ->andWhere('u.name like :query') 
      ->setParameter('query', "%".$query."%") 
     ; 
    } 

    if ($max) { 
     $qb ->setMaxResults($max) 
      ->setFirstResult($page * $max) 
     ; 
    } else { 
     $preparedQuery = $qb->getQuery(); 
    } 


    return $getResult?$preparedQuery->execute():$preparedQuery; 
} 

リソースソースはthis tutorialです。

どうすればこの問題を解決できますか?

答えて

0

応答だった:

$qb ->limit($to) 
     ->skip($from); 
関連する問題