lundi 26 septembre 2016

EmberJS API questions using PHP

I'm using Laravel/PHP to output some JSON for Ember to pick up.... a couple of things here.

First, my PHP looks like this (is there another way to send the data)

        return Response::json([
        'articles'  => $articles->toArray()
        ], $statusCode);   

This is what I am used to doing.

      foreach($articles as $article) {
         $response['articles'][] = [ 
            'id'    =>  $article->id,
            'body'  =>  $article->body,
            'title' =>  $article->title
        ];
     }

The first PHP snippet works fine, but the second does not. I get all kinds of errors about resource types by Ember.

Next question is for Ember heads. Right now I am getting everything working with RESTAdapter but should I be using JSONAPIAdapter instead? When I try to get it working with JSONAPIAdapter and JSONAPISerializer I get this error " One or more of the following keys must be present: \"data\", \"errors\", \"meta". I can get that error to go away but then I get an error about an undefined type or an unknown resource.




Aucun commentaire:

Enregistrer un commentaire