Nie chce zadziałać flush, w ogóle zawiesza mi całego xamppa i muszę go resetować żeby znów strona działała.
Nie wiem czemu, nie zwraca żadnego komunikatu, do momentu wywołania flush wszystko działa dobrze.
Oto kod który to wywołuje:
public function rateAction(Request $request)
{
$productId = $request->get('product_id');
$rate = $request->get('rate');
$em = $this->getDoctrine()->getManager();
$rateM= new RateM($em);
if($rateM->addRate($productId, $rate, $this->get('security.token_storage')->getToken()->getUser()))
{
$count = $em->getRepository('AppBundle:Rate')->getCountRate($productId);
$avgRate = $em->getRepository('AppBundle:Rate')->getAvgRate($productId);
$response = new JsonResponse();
$response->setData(array('avg' => $avgRate, 'count' => $count)); return $response;
}else{
$response = new JsonResponse();
$response->setData(array('error' => true)); return $response;
}
}
I w klasie RateM:
public function addRate($productId,$rate,$user)
{
$rate = new Rate();
$rate->setProduct($this->em->getRepository('AppBundle:Product')->findById($productId)[0]);
$rate->setRate($rate);
$rate->setUser($user);
$this->em->persist($rate);
try{
$this->em->flush(); // <- tu jest błąd jakiś
}catch(\Exception $e)
{
}
return true;
}
Blokuje mi to całą prace, chcę stworzyć system gwiazdkowy do oceniania obiektu.
Ten post edytował Crash89 22.11.2016, 16:26:06