Skip to content

Instantly share code, notes, and snippets.

Created October 31, 2016 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/143b585c375e1c1056cd66b668997907 to your computer and use it in GitHub Desktop.
Save anonymous/143b585c375e1c1056cd66b668997907 to your computer and use it in GitHub Desktop.
Série RestServer - Atualização do método index_get
/*
* 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