public function detailAction()
 {
     $id = $this->params()->fromRoute('id');
     try {
         $post = $this->postService->findPost($id);
     } catch (\InvalidArgumentException $ex) {
         return $this->redirect()->toRoute('post');
     }
     return new ViewModel(array('post' => $post));
 }
Ejemplo n.º 2
0
 /**
  * @return \Zend\Http\Response|ViewModel
  */
 public function editAction()
 {
     $request = $this->getRequest();
     $post = $this->postService->findPost($this->params('id'));
     $this->postForm->bind($post);
     if ($request->isPost()) {
         $this->postForm->setData($request->getPost());
         if ($this->postForm->isValid()) {
             try {
                 $this->postService->savePost($this->postForm->getData());
                 return $this->redirect()->toRoute('blog');
             } catch (\Exception $e) {
             }
         }
     }
     return new ViewModel(array('form' => $this->postForm));
 }
 public function deleteAction()
 {
     try {
         $post = $this->postService->findPost($this->params('id'));
     } catch (\InvalidArgumentException $e) {
         return $this->redirect()->toRoute('post');
     }
     $request = $this->getRequest();
     if ($request->isPost()) {
         $del = $request->getPost('delete_confirmation', 'no');
         if ($del === 'yes') {
             $this->postService->deletePost($post);
         }
         return $this->redirect()->toRoute('post');
     }
     return new ViewModel(array('post' => $post));
 }
Ejemplo n.º 4
0
 public function indexAction()
 {
     return new ViewModel(array('posts' => $this->postService->findAllPosts()));
 }
 public function indexAction()
 {
     //$this->getTaskMapper();
     return ["posts" => $this->postService->findAllPosts()];
 }