Esempio n. 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'));
        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;
    }