File tree Expand file tree Collapse file tree 1 file changed +5
-6
lines changed
Expand file tree Collapse file tree 1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -92,16 +92,15 @@ public function postShowAction(Post $post)
9292 */
9393 public function commentNewAction (Request $ request , Post $ post )
9494 {
95- $ form = $ this ->createForm (CommentType::class);
95+ $ comment = new Comment ();
96+ $ comment ->setAuthor ($ this ->getUser ());
97+ $ comment ->setPost ($ post );
98+
99+ $ form = $ this ->createForm (CommentType::class, $ comment );
96100
97101 $ form ->handleRequest ($ request );
98102
99103 if ($ form ->isSubmitted () && $ form ->isValid ()) {
100- /** @var Comment $comment */
101- $ comment = $ form ->getData ();
102- $ comment ->setAuthor ($ this ->getUser ());
103- $ comment ->setPost ($ post );
104-
105104 $ entityManager = $ this ->getDoctrine ()->getManager ();
106105 $ entityManager ->persist ($ comment );
107106 $ entityManager ->flush ();
You can’t perform that action at this time.
0 commit comments