Beispiel #1
0
 /**
  * Saves a post
  *
  * @param array $data
  * @return boolean
  **/
 public function save($data = array())
 {
     $data['content'] = str_replace(array('Â', ' '), '', $data['content']);
     $form = $this->getForm();
     $form->setData($data);
     if ($form->isValid()) {
         $post = $form->getData();
         $post->setDateModified(new DateTime());
         // Silly Doctrine.
         $categoryService = new CategoryService($this->em);
         $category = $categoryService->findById($post->getCategory()->getId());
         $post->setCategory($category);
         $this->em->persist($post);
         $this->em->flush();
         $this->addMessage('Successfully saved post.', self::MSG_NOTICE);
         return true;
     }
     $this->addMessage('Kindly fix the form errors.', self::MSG_ERROR);
     return false;
 }