2
I have an api that returns data from 1 user, but it returns an object:
[{"id":"0","nome":"xx","sobrenome":"xx","email":"x","senha":"xxx","unidadexlocal":"Praia da Costa","unidadecurricular":"2","diapreparacao":"1","liberadoexercicio":"0"}]
However as it is only a user, I wanted to return the array directly:
{"id":"0","nome":"xx","sobrenome":"xx","email":"x","senha":"xxx","unidadexlocal":"Praia da Costa","unidadecurricular":"2","diapreparacao":"1","liberadoexercicio":"0"}
'Cause so I don’t need to treat this as list on android, currently I’m having to do so: user.get(0).setnome
I want to do like this: user.setnome
Route with slimframwork in php:
$app->get('/aluno',function(Request $request,Response $response){
$usermail = $request->getHeader('PHP_AUTH_USER');
$senha = $request->getHeader('PHP_AUTH_PW');
$sql = new Sql();
$user = new Usuario();
$autenticado = $user->login($usermail[0],$senha[0]);
if ($autenticado) {
$resultado = $sql->select("SELECT * FROM tb_alunos WHERE email = :EMAIL LIMIT 1",array(
":EMAIL"=>$usermail[0]
));
$response = json_encode($resultado);
return $response;
}else{
return $response->withStatus(401);
}
});
do you consult with PDO? uses the
fetch()
orfetchAll()
?– rray
Yes, with Pdo, using Fetchall()
– Igor Oliveira