public function salvar(Cliente $objCliente) { $arrayDados = array_filter($objCliente->getArrayCopy()); $id = (int) $objCliente->getId(); $data = new \DateTime('now', new \DateTimeZone('America/Sao_Paulo')); if ($id == 0) { $arrayDados['criado'] = $data->format('Y-m-d H:i:s'); $arrayDados['modificado'] = $data->format('Y-m-d H:i:s'); return $this->insert($arrayDados); } else { if ($this->buscarUm($id)) { $arrayDados['modificado'] = $data->format('Y-m-d H:i:s'); return $this->update($arrayDados, ['id' => $id]); } throw new \Exception('Registro não encontrado.'); } }
public function salvarAction() { $form = $this->getClienteForm(); $request = $this->getRequest(); if ($request->isPost()) { $form->setData($request->getPost()); if ($form->isValid()) { $cliente = new Cliente(); $cliente->exchangeArray($form->getData()); $retorno = $this->getClienteTabela()->salvar($cliente); if ($retorno) { $this->flashMessenger()->addSuccessMessage("Registro salvo com sucesso."); return $this->redirect()->toRoute('cliente'); } else { $this->flashMessenger()->addErrorMessage("Erro ao salvar registro, tente novamentte."); } } } return array('form' => $form); }