1

I'm running into this effectively https://github.com/pixelandtonic/ElementAPI/issues/4 and I'm not quite sure how I'd integrate this change with https://gist.github.com/stevieg83/85dd058dc77a3b46764165975b17bb76 adding it as the first part of my function errors out for me

syntax error, unexpected '=>' (T_DOUBLE_ARROW)

What's missing?

2

100% untested, but try this:

return [
    'endpoints' => [
        'api/jobs.json' => function() {
            HeaderHelper::setHeader([
                'Access-Control-Allow-Origin' => 'http://example.com'
            ]);

            return [
                '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) {
            HeaderHelper::setHeader([
                'Access-Control-Allow-Origin' => 'http://example.com'
            ]);

            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,
                    ];
                },
            ];
        },
    ]
];
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.