Esempio n. 1
0
 /**
  * Edit my post
  *
  * @throws Zend_Controller_Action_Exception
  */
 public function editAction()
 {
     if (!($alias = $this->_getParam('alias'))) {
         throw new Zend_Controller_Action_Exception('Page not found');
     }
     $posts = new Blog_Model_Post_Table();
     if (!($post = $posts->getByAlias($alias))) {
         throw new Zend_Controller_Action_Exception('Post not found');
     }
     if (!$post->isOwner()) {
         throw new Zend_Controller_Action_Exception('Page is forbidden');
     }
     $form = new Blog_Form_Post_Edit();
     $form->setDefaults($post->toArray());
     if ($this->getRequest()->isPost() && $form->isValid($this->_getAllParams())) {
         $post->setFromArray($form->getValues());
         $post->save();
         $this->_helper->flashMessenger->addMessage('Post saved');
         $this->_helper->redirector->gotoRoute(array('alias' => $post->alias), 'blogpost');
     }
     $this->view->form = $form;
 }