Criação de ações de controladora para deletar, atualizar e criar novos elementos.
Esse commit está contido em:
@@ -69,4 +69,76 @@ class <?php echo $this->name ?>Controller extends Zend_Controller_Action
|
||||
|
||||
$this->view->result = $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function createAction()
|
||||
{
|
||||
$form = $this->getForm();
|
||||
if ($this->getRequest()->isPost()) {
|
||||
$data = $this->getRequest()->getPost();
|
||||
if ($form->isValid($data)) {
|
||||
$data = $form->getValues();
|
||||
$table = $this->getTable();
|
||||
$element = $table->createRow($data);
|
||||
$element->save();
|
||||
$this->_helper->redirector('index');
|
||||
}
|
||||
}
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function updateAction()
|
||||
{
|
||||
$table = $this->getTable();
|
||||
$id = (int) $this->_getParam('id', 0);
|
||||
$element = $table->find($id)->current();
|
||||
if ($element === null) {
|
||||
throw new Zend_Db_Exception('Invalid Element');
|
||||
}
|
||||
$form = $this->getForm();
|
||||
if ($this->getRequest()->isPost()) {
|
||||
$data = $this->getRequest()->getPost();
|
||||
if ($form->isValid($data)) {
|
||||
$data = $form->getValues();
|
||||
$element->setFromArray($data);
|
||||
$element->save();
|
||||
$this->_helper->redirector('index');
|
||||
}
|
||||
} else {
|
||||
$form->populate($element->toArray);
|
||||
}
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteAction()
|
||||
{
|
||||
$table = $this->getTable();
|
||||
$id = (int) $this->_getParam('id', 0);
|
||||
$element = $table->find($id)->current();
|
||||
if ($element === null) {
|
||||
throw new Zend_Db_Exception('Invalid Element');
|
||||
}
|
||||
$form = $this->getForm();
|
||||
if ($this->getRequest()->isPost()) {
|
||||
$element->delete();
|
||||
$this->_helper->redirector('index');
|
||||
}
|
||||
foreach ($form as $element) {
|
||||
$element->setAttrib('disabled','disabled');
|
||||
}
|
||||
$form->getElement('submit')->setAttrib('disabled', null)
|
||||
->setLabel('Deletar');
|
||||
$this->view->form = $form;
|
||||
}
|
||||
}
|
||||
Referência em uma Nova Issue
Bloquear um usuário