function delete($id = null) { App::Import('Model', 'Logmv'); $logmv = new Logmv(); App::Import('Model', 'User'); $users = new User(); App::Import('Model', 'Turma'); $turmas = new Turma(); if (!$id) { $this->Session->setFlash('Codigo Invalido para %s', 'flasherror'); $this->redirect(array('action' => 'index')); } $dados = $turmas->getTurmasByFuncionario($id); if (empty($dados)) { $user_id = $users->getUserByFuncionario($id); //var_dump($user_id[0]["us"]["id"]); $users = $users->deleteUser($user_id[0]["us"]["id"]); if ($this->Funcionario->delete($id)) { $this->Session->setFlash('Dados deletedos com sucesso ', 'flashok'); $this->redirect(array('action' => 'index')); } } $this->Session->setFlash('Nao e possivel apagar. Turmas associadas ao Funcionario', 'flasherror'); $this->redirect(array('action' => 'index')); }