How Is Model Passed To Server On Save in ember-data


#1

I am working on my own PHP backend and can’t figure out how to get the passed model via the PHP backend. I assumed it would be in eitther _GET, _POST, or $_SERVER so I var_dumped them all to the error log and nothing useful is there. ie. I am calling user.save() and looking at my PHP error log and don’t know where to grap the updated user information to push it to SQL. It would be nice to get help ASAP. Thanks!


#2

I am unable to understand the question. But can you look at the network tab to inspect the PUT/POST payload to see how ember-data is sending the model back on save?


#3

What kind of PHP framework are you using or did you make your own implementation?

Why I asked is because Ember Data passes data to the server according to the built-in conventions.

For example, if you have a User model, then by calling user.save() the next JSON will be POSTed to /users path on your server:

{
  "user": {
    "email": "tomster@emberjs.com",
    "password": "emberlove"
  }
}

As you didn’t mention where you’re trying to check for POSTed data, then obviously you should check for POST[“user”] on your /users path.


#4

I’d say every major PHP Framework has built-in solutions for this but if you’re using vanilla PHP you can access the request body with file_get_contents('php://input'). Combine it with json_decode() and you should be good to go!