Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [SF][SF2][Symfony2]Nie działa flush przy dodawaniu nowego rekordu
Crash89
post
Post #1





Grupa: Zarejestrowani
Postów: 191
Pomógł: 7
Dołączył: 3.04.2013

Ostrzeżenie: (0%)
-----


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:

  1. public function rateAction(Request $request)
  2. {
  3. $productId = $request->get('product_id');
  4. $rate = $request->get('rate');
  5.  
  6. $em = $this->getDoctrine()->getManager();
  7.  
  8. $rateM= new RateM($em);
  9. if($rateM->addRate($productId, $rate, $this->get('security.token_storage')->getToken()->getUser()))
  10. {
  11. $count = $em->getRepository('AppBundle:Rate')->getCountRate($productId);
  12. $avgRate = $em->getRepository('AppBundle:Rate')->getAvgRate($productId);
  13. var_dump('success');
  14. die();
  15. $response = new JsonResponse();
  16. $response->setData(array('avg' => $avgRate, 'count' => $count));
  17. return $response;
  18.  
  19. }else{
  20. var_dump('sfijasf');
  21. die();
  22. $response = new JsonResponse();
  23. $response->setData(array('error' => true));
  24. return $response;
  25. }
  26.  
  27.  
  28.  
  29. }
  30.  


I w klasie RateM:

  1. public function addRate($productId,$rate,$user)
  2. {
  3. $rate = new Rate();
  4.  
  5. $rate->setProduct($this->em->getRepository('AppBundle:Product')->findById($productId)[0]);
  6. $rate->setRate($rate);
  7. $rate->setUser($user);
  8. $this->em->persist($rate);
  9. try{
  10. $this->em->flush(); // <- tu jest błąd jakiś
  11. }catch(\Exception $e)
  12. {
  13. var_dump($e->getMessage());
  14. die();
  15. }
  16. var_dump($rate);
  17. die();
  18.  
  19.  
  20.  
  21. return true;
  22. }


Blokuje mi to całą prace, chcę stworzyć system gwiazdkowy do oceniania obiektu.

Ten post edytował Crash89 22.11.2016, 16:26:06
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 23.08.2025 - 11:03