1use AppBundle\Entity\Post; //at top of controller
2
3$em = $this->getDoctrine()->getManager();
4$user = $this->container->get('security.token_storage')->getToken()->getUser();
5$post = new Post();
6$em->persist( $post );
7$post->setOwner( $user );
8// set other fields in your post entity
9$em->flush();
10