0
symfony3アプリケーションでmongoDBを使用しています。私のリポジトリにsetMaxResults
とsetFirstResult
を使用してリスティングアクションのページ付けを行う必要があります。しかし、私はデータベースとして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です。
どうすればこの問題を解決できますか?