QueryBuilder 쿼리를 실행하려고하지만 for 루프의 "andWhere"구문이 마음에 들지 않습니다. 나는 for 루프에서 아무 것도 좋아하지 않는다고 생각한다. 배열 요소 중 하나라도 "x"와 같은지 확인하여이를 기반으로 검색 결과를 필터링합니다.Symfony 2 오류 : 배열의 멤버 함수 andWhere()를 호출합니다.
$repository = $this->getDoctrine()->getRepository('AppBundle:Shrubs');
$query = $repository->createQueryBuilder('p');
$shrubs = $query
->where($query->expr()->like('p.botanicalname', ':botanicalname'))
->setParameter('botanicalname', '%' . $botanicalname . '%')
->andwhere($query->expr()->like('p.commonname', ':commonname'))
->setParameter('commonname', '%' . $commonname . '%')
->orderBy('p.commonname', 'ASC')
->getQuery()
->getResult();
$checkfor = array("wetsoil"=>"Tolerates Wet Soil",
"borderlinehardy"=>"Borderline Hardy",
"moistsoil"=>"Prefers Moist Soil";
reset($checkfor);
foreach ($checkfor as $key => $value) {
if (${$key} == "x") {
$shrubs = $shrubs->andWhere('$key = x')
->setParameter('x', $key)
->getQuery()
->getResult();
return $this->render('shrubs/searchresults.html.twig', array(
'shrubs' => $shrubs,));
}
}
return $this->render('shrubs/searchresults.html.twig', array(
'shrubs' => $shrubs
getQuery() 실행하지 마십시오 -/전> getResult를을()에서 각각. – Maerlyn
시도해 봤는데, 작동하지 않았다 – bigmammoo