@Arky

Не получается запилить комментарии для блога, что делать?

Здравствуйте, я новичок в symfony. И у меня не получается запилить контроллер для отправки комментариев. На этот код, получаю ошибку
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()));
    }

Помогите пожалуйста.
  • Вопрос задан
  • 237 просмотров
Пригласить эксперта
Ответы на вопрос 1
@maxtm
Make money, not job
$post = $em->find('BlogBundle:Post', $this->$id);


Вероятнее всего имелось ввиду

$post = $em->find('BlogBundle:Post', $id);
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы