/** * Saves an article into the database. * * @param \DeadPoolCave\Domain\Article $article The article to save */ public function save(Article $article) { $articleData = array('art_title' => $article->getTitle(), 'art_content' => $article->getContent()); if ($article->getId()) { // The article has already been saved : update it $this->getDb()->update('t_article', $articleData, array('art_id' => $article->getId())); } else { // The article has never been saved : insert it $this->getDb()->insert('t_article', $articleData); // Get the id of the newly created article and set it on the entity. $id = $this->getDb()->lastInsertId(); $article->setId($id); } }