I am creating a web application that stores user’s journeys and I’m build this application in CakePHP 2.2.5.
I have a Journey model and that journey model has many coordinate objects which store the lat long coordinates.
I’d like to send an API call to the journey’s add method containing json in the body to create a new object.
I’ve tried to find out how to format the JSON to allow the controller to use it but I cant seem to find out. I’d also like to know how to add the child objects to the JSON.
I am testing the method using this cURL command
curl -i -H "ACCEPT: application/json" -X POST --data @/home/sam/data.json http://localhost/journeys/add.json
Running this CURL command create a blank entry in the database.
The JSON file included in the CURL contains
{"description" : "Hello World", "user_id":3}
I’ve done some more research and found a solution to my problem:
CakePHP will save JSON data and it will also save nested model information.
Which is similar to what @Arash said but it will also save nested model information by calling
The JSON I’m providing to the controller looks like:
Where coordinate belongs to Journey.