Last active
December 28, 2016 19:14
-
-
Save 1stevengrant/85dd058dc77a3b46764165975b17bb76 to your computer and use it in GitHub Desktop.
API generation for jobs using elementapi for CraftCMS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace Craft; | |
return [ | |
'endpoints' => [ | |
'api/jobs.json' => [ | |
'elementType' => 'Entry', | |
'criteria' => ['section' => 'jobs'], | |
'transformer' => function(EntryModel $entry) { | |
return [ | |
'title' => $entry->title, | |
'url' => $entry->url, | |
'jsonUrl' => UrlHelper::getUrl("jobs/{$entry->id}.json"), | |
]; | |
}, | |
], | |
'api/jobs/<entryId:\d+>.json' => function($entryId) { | |
return [ | |
'elementType' => 'Entry', | |
'criteria' => ['id' => $entryId], | |
'first' => true, | |
'transformer' => function(EntryModel $entry) { | |
return [ | |
'title' => $entry->title, | |
'url' => $entry->url, | |
'entryId' => $entry->id, | |
'postDate' => $entry->postDate, | |
]; | |
}, | |
]; | |
}, | |
] | |
]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment