/** * Método utilizado para editar Posts, testando a existência de uma requisão do tipo POST. * Seus valores são resgatados validados e atualizados no banco de dados. * @param int $id * @method updateAction * @access public * @return resource */ public function updateAction() { $form = new Application_Form_Post(); $form->setAction('/post/update'); $posts = new Application_Model_Posts(); if ($this->_request->isPost()) { if ($form->isValid($this->_request->getPost())) { $values = $form->getValues(); $posts->update($values, 'id = ' . $values['id']); $this->_redirect('post/retrieve'); } else { $form->populate($form->getValues()); } } else { $id = $this->_getParam('id'); $post = $posts->fetchRow("id ={$id}")->toArray(); $form->populate($post); } $this->view->form = $form; }
public function cadastrarAction() { $form = new Application_Form_Post(); $var = $this->getAllParams(); if ($this->getRequest()->isPost()) { if ($form->isValid($var)) { $dados = $form->getValues(); $inserir = array('idcategoria' => $dados['idcategoria'], 'titulo' => $dados['titulo'], 'texto' => $dados['texto']); $tb = new Application_Model_DbTable_Post(); $tb->insert($inserir); $this->_helper->redirector->gotoSimpleAndExit('index'); } } $this->view->form = $form; }
public function indexAction() { $form = new Application_Form_Post(); if ($this->getRequest()->isPost() && $form->isValid($this->getRequest()->getPost())) { if ($form->isValid($this->getRequest()->getPost())) { $post = new Application_Model_Post($form->getValues()); $post->save(); // reset the form $form->reset(); } } // show all posts $posts = new Application_Model_Post(); $this->view->form = $form; $this->view->posts = $posts->fetchAll(); }
public function editAction() { $this->view->form = $form = new Application_Form_Post(); $id = $this->_request->getParam('id', 0); if ($this->_request->isPost() && $id > 0) { $formData = $this->_request->getPost(); if ($form->isValid($formData)) { $post = new Application_Model_DbTable_Posts(); $post->updatePost($form->getValues(), $id); $this->_redirect('/post/index'); } else { $form->populate($formData); } } else { if ($id > 0) { $post = new Application_Model_DbTable_Posts(); $form->populate($post->getPost($id)); } } }