MyFantasy512
MyFantasy512

Reputation: 688

PHP ORM for Ember-Data [EmberJS]

I am looking for any PHP ORM library that pairs well with any Ember-Data serializer.

I want to write backend for my EmberJS app in PHP Slim-Framework, and I need model library which has backend or client adapter for Ember-Data.

I tried Eloquent ORM, but it's toJSON() functionallity isn't any close to any Ember-Data serializer.

Marcin

Upvotes: 0

Views: 113

Answers (1)

mpowered
mpowered

Reputation: 13526

I think you may be looking at this backwards. Serializers are meant to be customized for your API, not the other way around. But if you don't have an API yet, I would highly recommend doing your project on Rails API and either use active_model_serializers or RABL to serialize your responses. In Ember, you simply use DS.ActiveModelAdapter and you're off and running.

I used to be a PHP guy, but I dove into Rails for my latest project and never looked back. I would highly recommend trying it if you're greenfielding a project, Rails/the Ruby community have figured out a TON of things that the PHP guys are struggling to keep up with. Not dealing with composer and shitty modules is also a big plus.

If you're sticking with PHP, then you can easily still use DS.RESTAdapter and DS.ActiveModelAdapter really easily:

{
  "users": [
    {
      "id": 12,
      "first_name": "La la"
    },
    {
      "id": 13,
      "first_name": "Tra la"
    }
  ],
  "posts": [
    {
      "id": 1,
      "author_id": 12,
      "title": "My vacation"
    },
    {
      "id": 2,
      "author_id": 13,
      "title": "Why I love Rails API"
    }

There's no secret to the JSON format, your server just needs a serializer that matches the expectation of whatever serializer you're using in Ember Data.

Upvotes: 0

Related Questions