The Slim Framework support forum has moved to http://discourse.slimframework.com.
This Tender forum is no longer maintained or monitored.
Error with JSON
Hello every body , im using Slim Framework 3.
It's my first time with a framework.
I'm trying to dev a little API REST .
Here my code
function GetNewsFct(Request $request,Response $reponse){
$retour = array("result"=>0);
$list = array();
$sql = " SELECT news_id,news_date,news_titlefr,news_titlenl,news_contentfr,news_contentnl
FROM news
ORDER BY news_date LIMIT 5,20";
try {
$id=42;
$db = getDb();
$req = $db->prepare($sql);
//$req->bindParam("id",$id,PDO::PARAM_INT);
$req->execute();
$result=$req->fetchAll();
foreach($result as $k=>$v){
$list[] = array( "new_id" => $v['news_id'],
"date" => $v['news_date'],
"titlefr" => addslashes($v['news_titlefr']),
"text" => addslashes($v['news_contentfr'])
);
}
$retour = $list;
} catch(PDOException $e) {
$retour ='{"error":{"text":'. $e->getMessage() .'}}';
}
$newResponse = $reponse->withJson($retour);
return $newResponse;
}
That should return a good json
But that's return something like that [ somthing ** WITHOUT THE ]... when i reduce my array size... that's ok ... have an idea?
Sorry for my english im french
Comments are currently closed for this discussion. You can start a new one.
Keyboard shortcuts
Generic
? | Show this help |
---|---|
ESC | Blurs the current field |
Comment Form
r | Focus the comment reply box |
---|---|
^ + ↩ | Submit the comment |
You can use Command ⌘
instead of Control ^
on Mac
Josh Lockhart closed this discussion on 12 Feb, 2021 07:37 PM.