根据教义,我生成了一个控制器来显示电影标题。
我有这个错误
[语法错误] 第 0 行,列 52:错误:预期 =, <, <=, <>,>,>=, !=, 得到 '%'
第一个代码有效,但第二个代码不显示偶数年。 为什么?
/** Mostrare i film usciti tra il 1980 e il 1990
*
* @Route("/findBetweenYears/{yearStart}/{yearStop}", name ="movie_between")
* @Method("GET")
*
*/
public function showMovieBetweenAction($yearStart,$yearStop){
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$qb->select('m')
->from(Movie::class,'m')
->where('m.year >= 1980 and m.year <=1990');
$movies = $qb->getQuery()->getResult();
return $this->render('movie/yearshow.html.twig',array(
'movies' => $movies,
));
}
/** Mostrare i film usciti in un anno pari
*
* @Route("/findEvenYears/{year}", name = "movie_even")
* @Method("GET")
*
*/
public function showMovieYearEven(){
$em = $this->getDoctrine()->getManager();
$qb = $em->createQueryBuilder();
$qb->select('m')
->from(Movie::class,'m')
->where('m.year % 2 = 0');
$movies = $qb->getQuery()->getResult();
return $this->render('movie/yeareven.html.twig',array(
'movies' => $movies
));
}
DQLmod
教义在文档中定义为
MOD(a, b) - 返回一个 MOD b。
意思是你应该把它用作
->where('MOD(m.year, 2) = 0')