private function edit() { $this->error = false; $this->msg = false; $this->v = array('_name' => '', '_branch' => '', '_phone' => ''); if (isset($_GET['id']) && $_GET['id']) { $id = (int) $_GET['id']; $model = new Model_client(); $client = $model->get_client($id); $client = array_shift($client); if (!$client) { $this->error = 'Cliente não encontrado! '; } } if (isset($_POST['client-form']) && $_POST['client-form']) { $requires = array('_name', '_branch', '_phone'); $values = $this->sanitize_fields($_POST, $requires); if (!$values) { $this->error = 'Preencha todos os campos! '; } } if (isset($values) && $values && isset($id)) { $values['_id'] = (int) $id; $result = $model->update_client($values); if ($result) { $this->msg = 'Cliente editado com sucesso'; $client = $model->get_client($values['_id']); $client = array_shift($client); } } if (isset($client) && !empty($client)) { $this->v = array('_name' => $client->client_name, '_branch' => $client->client_branch, '_phone' => $client->client_phone); } else { $this->error = 'Ocorreu um erro ao atualizar o cliente! '; $this->v = array('_name' => $_POST['_name'], '_branch' => $_POST['_branch'], '_phone' => $_POST['_phone']); } if (isset($model->error)) { $this->error .= $model->error; } include_once "view/client-insert.php"; }