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.
public function commentAction($postId, Request $request){
$comment = new Comment();
$form = $this->createFormBuilder($comment)
->add('content', 'textarea')
->getForm();
$form->handleRequest($request);
$userId = $this->get('security.context')->getToken()->getUser()->getId();
if ($request->getMethod() == 'POST') {
$em = $this->getDoctrine()->getEntityManager();
$comment->setPostId($postId);
$comment->setDate($now);
$comment->setUserId($userId);
$em->persist($comment);
$em->flush();
}
class Comment {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
protected $id;
/**
* @ORM\Column(type="integer")
*/
protected $user_id;
/**
* @ORM\Column(type="string")
*/
protected $content;
/**
* @ORM\Column(type="integer")
*/
protected $date;
/**
* @ORM\Column(type="integer")
*
*/
protected $post_id;
/**
* @ORM\ManyToOne(targetEntity="User", inversedBy="comment")
* @ORM\JoinColumn(name="user_id", referencedColumnName="id")
*/
protected $users;
/**
* @ORM\ManyToOne(targetEntity="Post", inversedBy="comment")
* @ORM\JoinColumn(name="post_id", referencedColumnName="id")
*/
protected $posts;
Czy ktoś wie w czym tkwi problem? Proszę o pomoc.