public function cadastrarjsonAction() { $retorno = new stdClass(); try { $retorno->new_id = $this->salvar(new Application_Model_Local($this->getRequest()->getParams())); //busca os locais $local = new Application_Model_DbTable_Local(); $retorno->locals = $local->fetchAll(null, 'nome asc')->toArray(); //$retorno->locals = $retorno->locals.toArray(); $retorno->ok = TRUE; } catch (Exception $exc) { $retorno->erro = new stdClass(); $retorno->erro->message = $exc->getMessage(); $retorno->erro->code = $exc->getCode(); $retorno->ok = FALSE; } finally { $this->_helper->json($retorno); } }
public function editarAction() { $id = $this->getRequest()->getParam('id'); if (!$id || !is_numeric($id)) { $this->view->alert = array('tipo' => 'danger', 'titulo' => "Alerta", 'msg' => "ID inválido."); return $this->indexAction(); } $prodDB = new Application_Model_DbTable_Produto(); $res = $prodDB->find($id)->toArray(); if (count($res) != 1) { $this->view->alert = array('tipo' => 'danger', 'titulo' => 'Alerta', 'msg' => 'Produto não encontrado.'); return $this->indexAction(); } $this->view->produto = $res[0]; $local = new Application_Model_DbTable_Local(); $this->view->locals = $local->fetchAll(null, 'nome asc'); if ($this->getRequest()->isPost()) { $error = $this->validaPost(); if (count($error) > 0) { $this->view->msg = "Atualização não realizado"; $this->view->errors = $error; } else { $dados = $this->getRequest()->getParams(); //@TODO change this code to a better place a function on a static Class unset($dados['module']); unset($dados['controller']); unset($dados['action']); unset($dados['id']); $dados['preco'] = str_replace(',', '.', $dados['preco']); $prodDB->update($dados, array('id=?' => $id)); $this->view->msg = "Atualização realizado com sucesso"; return $this->indexAction(); } } $this->renderScript('produto/cadastrar.phtml'); }
public function cadastrarAction() { $local = new Application_Model_DbTable_Local(); $this->view->locals = $local->fetchAll(null, 'nome asc'); if ($this->getRequest()->isPost()) { $error = array(); $prodModel = new Application_Model_Produto($this->getRequest()->getParams()); if (!$prodModel->getLocal_id()) { $error['local_id'] = 'Por Favor Insira um local válido.'; } if (!$prodModel->getNome()) { $error['nome'] = 'Por Favor Insira um nome válido.'; } if (count($error) > 0) { $this->view->msg = "Cadastro não realizado"; $this->view->errors = $error; return; } $proDB = new Application_Model_DbTable_Produto(); $proDB->insert($prodModel->__toArray()); $this->view->msg = "Produto Cadastrado com sucesso."; $this->renderScript('produto/salvar.phtml'); } }
function listarAction() { $local = new Application_Model_DbTable_Local(); $this->view->locals = $local->fetchAll(null, 'nome asc'); $this->renderScript('local/listar.phtml'); }