5
I’m making a requisition the following way.
http://localhost/sistema-agenda-server/tarefas/listAll?id=1
I asked to see in the answer the generated sql and got the following answer:
SELECT * FROM tarefas WHERE idu_tar=:id
:id has not been changed to 1.
public function get_listAll($id = null, $filtroData = null, $filtroDuracao = null, $ordem = null)
{
$sql = "SELECT * FROM tarefas WHERE idu_tar=:id ";
$vars = array(':id' => $id);
if(!is_null($filtroData))
{
$sql .= " AND datf_tar = :filtroData";
$vars[':filtroData'] = $filtroData;
}
if(!is_null($filtroDuracao))
{
$sql .= " AND tee_tar = :filtroDuracao";
$vars[':filtroDuracao'] = $filtroDuracao;
}
if(!is_null($ordem))
{
$sql .= " ORDER BY :ordem";
$vars[':ordem'] = $ordem;
}
else
{
$sql .= " ORDER BY gra_tar";
}
$stmt = DB::prepare($sql);
$stmt->execute($vars);
$tarefas = $stmt->fetchAll();
if($tarefas != null)
return $tarefas;
else
throw new Exception("Erro ao obter tarefas!");
}
If I change:
$vars = array(':id' => $id);
for $vars = array(':id' => $_GET['id'])
;
works.
I believe it is something simple. Someone can help me?
This is the route according to the controller specification, action and the parameter , for my classes:
$app->get('/:controller/:action(/:parameter)',
function ($controller, $action, $parameter = null) use($app){
include_once "classes/{$controller}.php";
$classe = new $controller();
$retorno = call_user_func_array(array($classe, "get_" . $action), array($parameter));
echo '{"result":' . json_encode($retorno) . '}';
});
as this called
get_listAll
, 'Cause as far as I can tell it should be something like this:get_listAll($_GET['id'], ...)
, am I correct? Read this: http://answall.com/help/mcve - follow the tips on the link, otherwise it will be difficult to help. I’m sure you’ll understand my comment as a constructive criticism :)– Guilherme Nascimento
Show how you make the call of this method. o
execute()
does not return error?– rray
$_GET['id'] is the right one. If it works without $_GET, it’s a poorly configured hosting signal (or a test-only local server, of course), without proper security care.
– Bacco
Is this what William Nascimento is asking me? $app->get('/:controller/:action(/:Parameter)', Function ($controller, $action, $Parameter = null) use($app) { include_once "classes/{$controller}. php"; $class = new $controller(); $return = call_user_func_array(array($class, "get_" . $action), array($Parameter)); echo '{"result":' . json_encode($return) . '}'; });
– Pedro Lima
I’m using the slim framework
– Pedro Lima
Edit the question and place these codes of comments.
– rray