json_encode a notORM table

54 views
Skip to first unread message

Pierre DUOT

unread,
Apr 14, 2016, 4:42:29 AM4/14/16
to NotORM
Hello,
I want to return en json result of your application table containing an array of tags for each item

$applications = $db->application();
foreach ($applications as $application) { // get all applications
    $listTag
= [];
   
foreach ($application->application_tag() as $application_tag) { // get all tags of $application
        $listTag
[] = $application_tag->tag["name"]);
   
}
    $application
['tags'] = $listTag;
}
echo json_encode
($applications);


It doesn't work. Why ?

It's working for a single item :
    $listTag = [];
    $application = $db->application[$id];
   
foreach ($application->application_tag() as $application_tag) { // get all tags of $application
        $listTag
[] = $application_tag->tag["name"]);
   
}
    $application
['tags'] = $listTag;
    echo json_encode
($application);





Jeremy Curny

unread,
Apr 14, 2016, 8:47:22 AM4/14/16
to NotORM
Hi,

You put $listTag in $application, and you json_encode the $applications (plurial) who isn't modified.
Reply all
Reply to author
Forward
0 new messages