Created
October 31, 2016 18:04
-
-
Save anonymous/143b585c375e1c1056cd66b668997907 to your computer and use it in GitHub Desktop.
Série RestServer - Atualização do método index_get
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Essa função vai responder pela rota /api/usuarios sob o método GET | |
*/ | |
public function index_get() | |
{ | |
// Recupera o ID diretamente da URL | |
$id = (int) $this->uri->segment(3); | |
// Valida o ID | |
if ($id <= 0) | |
{ | |
// Lista os usuários | |
$usuarios = $this->UsuariosMDL->GetAll('id, nome, email'); | |
} else { | |
// Lista os dados do usuário conforme o ID solicitado | |
$usuarios = $this->UsuariosMDL->GetById($id); | |
} | |
// verifica se existem usuários e faz o retorno da requisição | |
// usando os devidos cabeçalhos | |
if ($usuarios) { | |
$response['data'] = $usuarios; | |
$this->response($response, REST_Controller::HTTP_OK); | |
} else { | |
$this->response(null,REST_Controller::HTTP_NO_CONTENT); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment