Created
May 23, 2011 19:34
-
-
Save eminetto/987383 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//faz a edição de um post | |
public function editAction() { | |
$session = Zend_Registry::get('session'); | |
$form = new PostForm(); | |
//muda o label do submit | |
$form->submit->setLabel('Alterar'); | |
//muda a action | |
$form->setAction(BASE_URL.'/admin/admin/edit')->setMethod('post'); | |
//busca o id do post que vai ser alterado | |
$id = $this->_getParam('id'); | |
$posts = new Posts(); | |
if ($this->_request->isPost()) { //salvar os dados | |
$formData = $this->_request->getPost(); | |
//formulário está valido | |
if ($form->isValid($formData)) { | |
$dados = array( | |
'title' => $formData['title'], | |
'description' =>$formData['description'] | |
); | |
$posts->update($dados,"id = ".$formData['id']); | |
$session->erro ="Post alterado com sucesso"; | |
$this->_redirect('/admin/admin'); //redireciona para a página inicial | |
} | |
else { | |
// Mostra os erros e popula o form com os dados enviados | |
$form->populate($formData); | |
} | |
} | |
else { //mostrar os dados | |
//preenche os dados do formulário com os dados vindos do banco | |
$form->populate($posts->fetchRow("id = $id")->toArray()); | |
} | |
$this->view->form = $form; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment