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)
92
92
*/
93
93
public function commentNewAction (Request $ request , Post $ post )
94
94
{
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 );
96
100
97
101
$ form ->handleRequest ($ request );
98
102
99
103
if ($ form ->isSubmitted () && $ form ->isValid ()) {
100
- /** @var Comment $comment */
101
- $ comment = $ form ->getData ();
102
- $ comment ->setAuthor ($ this ->getUser ());
103
- $ comment ->setPost ($ post );
104
-
105
104
$ entityManager = $ this ->getDoctrine ()->getManager ();
106
105
$ entityManager ->persist ($ comment );
107
106
$ entityManager ->flush ();
You can’t perform that action at this time.
0 commit comments