/** * Creates an Article object based on a DB row. * * @param array $row The DB row containing Article data. * @return \Portfolio\Domain\Model\Article */ protected function buildDomainObject($row) { $article = new Article(); $article->setId($row['id']); $article->setTitle($row['title']); $article->setContent($row['content']); $article->setPublishedDate($row['publishedDate']); $article->setAuthor($row['author']); $article->setImage($row['image']); $article->setPublished($row['published']); return $article; }
/** * @param Request $request * @param Application $app * @return \Symfony\Component\HttpFoundation\RedirectResponse */ public function addAction(Request $request, Application $app) { $user = $app['security']->getToken()->getUser(); $article = new Article(); $article->setAuthor($user->getId()); $articleForm = $app['form.factory']->create(new ArticleForm(), $article); $articleForm->handleRequest($request); if ($articleForm->isValid()) { $filename = $this->upload($request, $articleForm, 900, 300); $article->setImage($filename); $this->repository['articleRepository']->save($article); $app['session']->getFlashBag()->add('success', 'The article was successfully created.'); return $app->redirect($app["url_generator"]->generate('listArticle')); } return $app['twig']->render('Pages/Article/Add.html.twig', array('title' => 'New article', 'articleForm' => $articleForm->createView())); }