Answer the question
In order to leave comments, you need to log in
I can't write comments for the blog, what should I do?
Hello I am new to symfony. And I can't get the controller to send comments. For this code, I get an error
Notice: Undefined property: Blogger\BlogBundle\Controller\BlogController::$20
/**
* @Route("/posts/{id}", name="post")
*/
public function postAction(Request $request, $id){
$post = $this->getDoctrine()
->getRepository(Post::class)
->find($id);
$comment = new Comment();
$comment->setBody('Write a comment');
$comment->setCreated(\date('Y:m:d в H:i:s'));
$form = $this->createFormBuilder($comment)
->add( 'body',TextareaType::class)
->add('save',SubmitType::class, array('label' => 'Отправить'))
->getForm();
$form->handleRequest($request);
if ($form->isValid() && $form->isSubmitted()){
$task = $form->getData();
$em = $this->getDoctrine()->getManager();
$post = $em->find('BlogBundle:Post', $this->$id);
$post->comment($task);
$em->persist($task);
$em->flush();
return $this->redirectToRoute('post');
}
return $this->render('BlogBundle:Blog:show.html.twig', array('result' => $post, 'form' => $form->createView()));
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question