A
A
Arky2017-10-11 19:12:53
symfony
Arky, 2017-10-11 19:12:53

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()));
    }

Help me please.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Night, 2017-10-11
@maxtm

$post = $em->find('BlogBundle:Post', $this->$id);

Most likely meant
$post = $em->find('BlogBundle:Post', $id);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question