The Slim Framework support forum has moved to This Tender forum is no longer maintained or monitored.

Error with JSON

ledent.n's Avatar


31 Mar, 2016 11:38 AM

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 {
    $db = getDb();
    $req = $db->prepare($sql);
    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

  1. Josh Lockhart closed this discussion on 12 Feb, 2021 07:37 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts


? 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