a-ok Posted March 27, 2017 Share Posted March 27, 2017 I realise this may be a generic JSON/PHP question but I want to make sure I'm harnessing the API correctly from the beginning. I want to create a JSON data output of pages of my site, as well as individual pages, but I'm unsure how to do this as one whole output. I know and can output, for example, projects within a project, but how do I also output the homepage content, and other page content, at the same time? The JSON output would include things like 'home' and 'project' arrays but would be blank if you aren't viewing the homepage and or project page... if that makes sense. $projects_array = array( 'projects' => array() ); $projects = $pages->find('template=projects-detail, sort=sort'); foreach ($projects as $project) { $project_content = array( 'id' => $project->id, 'title' => $project->title, 'name' => $project->name, 'size' => $project->projects_categories_projects_size, 'img' => array( 'featured' => $project->projects_detail_featured_image->url ) ); array_push($projects_array['projects'], $project_content); } $projects_json = json_encode($projects_array, true); Link to comment Share on other sites More sharing options...
LostKobrakai Posted March 27, 2017 Share Posted March 27, 2017 You might want to look into this package: http://fractal.thephpleague.com/ Link to comment Share on other sites More sharing options...
a-ok Posted March 27, 2017 Author Share Posted March 27, 2017 51 minutes ago, LostKobrakai said: You might want to look into this package: http://fractal.thephpleague.com/ I think this still gives me the same problem... I'd still need to build the data as JSON before passing it into fractal. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now