Ejemplo n.º 1
0
 /**
  * Edit action
  *
  */
 public function editAction()
 {
     $post = new Post();
     if ($this->params('id') > 0) {
         $post = $this->getEntityManager()->getRepository('Blog\\Entity\\Post')->find($this->params('id'));
     }
     $form = new PostForm($this->getEntityManager());
     $form->setHydrator(new DoctrineEntity($this->getEntityManager(), 'Blog\\Entity\\Post'));
     $form->bind($post);
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter($post->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $em = $this->getEntityManager();
             $em->persist($post);
             $em->flush();
             $this->flashMessenger()->addSuccessMessage('Post Saved');
             $this->flashMessenger()->addMessage('sadf');
             $this->flashMessenger()->addErrorMessage('2312');
             return $this->redirect()->toRoute('post');
         }
     }
     return new ViewModel(array('post' => $post, 'form' => $form));
 }
Ejemplo n.º 2
0
 /**
  * To update/edit a blog post
  *
  * @parmam void
  * @return ViewModel
  * @throws AccessProhibitedException
  **/
 public function editAction()
 {
     $this->_checkAcl('edit');
     $request = $this->getRequest();
     $post = $this->_postService->getFromId($request->getQuery('id'));
     $categoryService = new CategoryService($this->_em);
     $form = new PostForm();
     $form->bind($post);
     $form->setCategoryList($categoryService->getAll());
     $this->_postService->setForm($form);
     if ($request->isPost()) {
         $this->_postService->save($request->getPost());
     }
     return new ViewModel(array('form' => $form, 'post' => $post, 'messages' => $this->_postService->getMessages(PostService::MSG_NOTICE), 'errors' => $this->_postService->getMessages(PostService::MSG_ERROR)));
 }
Ejemplo n.º 3
0
 public function editAction()
 {
     $id = (int) $this->params('id');
     if (!$id) {
         return $this->redirect()->toRoute('posts', array('action' => 'new'));
     }
     try {
         $post = $this->getPostTable()->getPost($id);
     } catch (\Exception $ex) {
         return $this->redirect()->toRoute('posts', array('action' => 'index'));
     }
     $table = $this->getServiceLocator()->get('Blog\\Model\\CategoryTable');
     $form = new PostForm($table);
     $form->bind($post);
     $form->get('submit');
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setInputFilter($post->getInputFilter());
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $this->getPostTable()->savePost($post);
             return $this->redirect()->toRoute('posts', array('action' => view, 'id' => $id));
         }
     }
     return array('id' => $id, 'form' => $form, 'post' => $post);
 }