public function createAction(Request $request, Application $app)
 {
     if (!$request->request->has('title')) {
         return $app->json('Missing required parameter: title', 400);
     }
     if (!$request->request->has('content')) {
         return $app->json('Missing required parameter: content', 400);
     }
     $article = new Article();
     $article->setTitle($request->request->get('title'));
     $article->setContent($request->request->get('content'));
     $app['dao.article']->save($article);
     $responseData = array('id' => $article->getId(), 'title' => $article->getTitle(), 'content' => $article->getContent());
     return $app->json($responseData, 201);
 }
Example #2
0
 public function save(Article $article)
 {
     $articleData = array('title' => $article->getTitle(), 'content' => $article->getContent());
     if ($article->getId()) {
         $this->db->update('article', $articleData, array('id' => $article->getId()));
     } else {
         $this->db->insert('article', $articleData);
         $id = $this->getDb()->lastInsertId();
         $article->setId($id);
     }
 }