ページネーションを実行しようとしていますが、エラーがあります。
[構文エラー]行0、列57:エラー:文字列の終わりが必要です。「制限」を取得しました
これが私のクエリを作成するための正しい構文(およびロジック)であるかどうかはよくわかりません。
public function getFriendsFromTo ($user, $limit, $offset)
{
return $this->getEntityManager()
->createQuery('SELECT f FROM EMMyFriendsBundle:Friend f WHERE f.user='.$user.' limit '.$limit. 'offset' .$offset)
->getResult();
}
友達とユーザーはmanyToOneとoneToManyに関連しているため、friendsテーブルにはフィールドuser_idがあります。
これは私のコントローラーにあります:
$user = $this->get('security.context')->getToken()->getUser();
$id = $user->getId();
$friends = $user->getFriends();
$result = count($friends)
$FR_PER_PAGE = 7;
$pages = $result/$FR_PER_PAGE;
$em = $this->getDoctrine()->getEntityManager();
$friends = $em->getRepository('EMMyFriendsBundle:Friend')
->getFriendsFromTo($id, $FR_PER_PAGE, $page*$FR_PER_PAGE);
私はそれが愚かで間違っていることを知っていますが(特に3番目のパラメーター$page*$FR_PER_PAGE
)、クエリが機能するかどうかを試してみたかったのですが、機能しませんでした。