php - Customizing JSON output in CakePHP -
In KPPHP 2.4, to optimize the correct syntax for foreach
through my data What is the structure of JSON output from the content and my controller?
I currently have the following method, which is Generates JSN which directly reflects the internal array of cake from all of my posts:
public function digits () {$ this-> Autorander = False; // We do not render this view in this example $ -This-> Post- & gt; Recursive = -1; // To not return the content, return us json_encode ($ this-> Post- & gt; search ('all' is not required); }
This creates JSON which looks like this, with the data of each post, children of their own post object (pre-determined with the carriage return so that you can read it): "Label",>
"Code": [{"id": "1", "user_id": "1", "organism_id": "0", "title": "title text", "latitude": "44.54401744186992" , "LNG": "- 68.26070404052734", "Body": " "2014-01-19 07:13:" 0 "," title ":" "," modified ":" 2014-01-19 07:13:29 "}, {" id "", "User_id": "1", "organism_id": "body text", "created": "2014-01-19 07:13:29", "title text", "latitude": " 44.54401744186992 "," LNG ":" - 68.26070404052734 "," Modified ":" 2014-01-19 07:13:29 "}]}
I know that in any way Need data via foreach
and create an array. how does it work? foreach ($ post as $ post):
does not work inside the controller.
try it ......
$ data = Array (); Foreign Currency ($ post $ post) {$ data [] = $ post ['post']; } $ Postdata ['post'] = $ data; Echo json_encode ($ postdata);
Comments
Post a Comment