The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Error with JSON

ledent.n's Avatar

ledent.n

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 {
    $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

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

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