Exemple #1
0
    private function savePost($request): Post
    {
        $post = new Post();
        $user = $this->userSession->getUser();
        $user = $this->em->find("App\Model\User", $user->getId());
        $post->setUser($user);
        $post->setTitle($request->get('title'));
        $post->setDescription($request->get('description'));
        $post->setPostedAt(new \DateTime('now'));
        $this->em->persist($post);
        $this->em->flush();

        return $post;
    }
Exemple #2
0
    public function submitPostAction(Request $request): Response
    {
        if ($this->form->isValid($request)) {

            $post = new Post();
            $user = $this->userSession->getUser($this->session);
            $user = $this->em->find("App\Model\User", $user->getId());
            $post->setUser($user);
            $post->setTitle($request->get('title'));
            $post->setDescription($request->get('description'));
            $post->setPostedAt(new \DateTime('now'));
            $this->em->persist($post);
            $this->em->flush();

            return new Response($this->twig->render('post_success.html.twig'));

        }

        $this->setFlashMessages('errors', $this->form->getErrors());

        return new RedirectResponse(
            $this->urlGenerator->generate('post')
        );
    }
Exemple #3
0
    private function savePost($request): Post
    {
        $post = new Post();
        $user = $this->userSession->getUser();
        $user = $this->em->find("App\Model\User", $user->getId());
        $post->setUser($user);
        $post->setTitle($request->get('title'));
        $post->setDescription($request->get('description'));
        if ($imageName = $request->get('imageName')) {
            rename($this->uploadDir.'/temp/'.$imageName, $this->uploadDir.'/'.$imageName);
            $post->setImage($imageName);
        }
        $post->setPostedAt(new \DateTime('now'));
        $this->em->persist($post);
        $this->em->flush();

        return $post;
    }