Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [SF][SF2][Symfony2]persist- puste wartosci
Forum PHP.pl > Forum > PHP > Frameworki
gentleman
Witam, posiadam pewien problem. Podczas wysyłania komentarza data i treść komentarza zostają poprawnie ustawione, jednak wartości UserId i PostId są puste. Zwraca null nawet gdy są ustawione na 1.

  1. public function commentAction($postId, Request $request){
  2. $comment = new Comment();
  3. $form = $this->createFormBuilder($comment)
  4. ->add('content', 'textarea')
  5. ->getForm();
  6.  
  7. $form->handleRequest($request);
  8.  
  9. $userId = $this->get('security.context')->getToken()->getUser()->getId();
  10.  
  11. $now = time();
  12.  
  13. if ($request->getMethod() == 'POST') {
  14. $em = $this->getDoctrine()->getEntityManager();
  15. $comment->setPostId($postId);
  16. $comment->setDate($now);
  17. $comment->setUserId($userId);
  18. $em->persist($comment);
  19. $em->flush();
  20. }


  1. class Comment {
  2.  
  3. /**
  4.   * @ORM\Id
  5.   * @ORM\Column(type="integer")
  6.   * @ORM\GeneratedValue(strategy="AUTO")
  7.   */
  8. protected $id;
  9.  
  10. /**
  11.   * @ORM\Column(type="integer")
  12.   */
  13.  
  14. protected $user_id;
  15.  
  16. /**
  17.   * @ORM\Column(type="string")
  18.   */
  19.  
  20. protected $content;
  21.  
  22. /**
  23.   * @ORM\Column(type="integer")
  24.   */
  25.  
  26. protected $date;
  27.  
  28. /**
  29.   * @ORM\Column(type="integer")
  30.   *
  31.   */
  32.  
  33. protected $post_id;
  34.  
  35. /**
  36.   * @ORM\ManyToOne(targetEntity="User", inversedBy="comment")
  37.   * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  38.   */
  39.  
  40. protected $users;
  41.  
  42. /**
  43.   * @ORM\ManyToOne(targetEntity="Post", inversedBy="comment")
  44.   * @ORM\JoinColumn(name="post_id", referencedColumnName="id")
  45.   */
  46.  
  47. protected $posts;


Czy ktoś wie w czym tkwi problem? Proszę o pomoc.
pedro84
Po pierwsze, http://docs.doctrine-project.org/en/latest...cade-operations.
Po drugie, zobacz sobie co akceptują gettery w tej encji.
Po trzecie, w innym temacie Ci już pisałem, masz niepoprawne nazwy składowych.
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.