示例#1
0
 public function create($data)
 {
     $form = new AlbumForm();
     $album = new \Application\Entity\Album();
     $form->setInputFilter($album->getInputFilter());
     $form->setData($data);
     if ($form->isValid()) {
         $album->setOptions($form->getData());
         // set the data
         $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
         // entity manager
         $em->persist($album);
         // set data
         $em->flush();
         // save
     }
     return new JsonModel(array('data' => $album->toArray()));
 }
示例#2
0
 public function addAction()
 {
     $album = new \Application\Entity\Album();
     $form = new AlbumForm();
     $form->setInputFilter($album->getInputFilter())->setData($this->getRequest()->getPost())->get('submit')->setValue('Add');
     if ($this->getRequest()->isPost() && $form->isValid()) {
         $album->setOptions($form->getData());
         // set the data
         $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager');
         // entity manager
         $em->persist($album);
         // set data
         $em->flush();
         // save
         // set messages
         //$this->flashMessenger()->addMessage('You must do something.');
         //$this->flashMessenger()->addMessage(array('alert-info'=>'Soon this changes.'));
         $this->flashMessenger()->addMessage(array('alert-success' => 'Added!'));
         //$this->flashMessenger()->addMessage(array('alert-error'=>'Sorry, Error.'));
         // Redirect to list of albums
         return $this->redirect()->toRoute('admin/album');
     }
     return array('form' => $form);
 }