Closed DowleyDeveloped closed 2 years ago
The endpoint config should go in config/element-api.php
using the format shown in this example: https://github.com/craftcms/element-api#setup
So something like:
use verbb\events\elements\Event;
use verbb\events\models\EventType;
return [
'endpoints' => [
'events.json' => function() {
return [
'elementType' => Event::class,
'criteria' => [
'type' => Craft::$app->request->getQueryParam('section') ?? 'event',
'offset' => Craft::$app->request->getQueryParam('offset') ?? 0,
],
'elementsPerPage' => Craft::$app->request->getQueryParam('items') ?? 10,
'transformer' => function(Event $event) {
return [
'title' => $event->title,
];
},
];
},
],
];
Hi,
Apologies I set up the endpoint config set up and the above goes into another file:
use config\endpoints\Collections; use config\endpoints\Events;
return [
'endpoints' => [
'api/collections.json' => function() {
return Collections::index();
},
'api/events.json' => function() {
return Events::index();
},
]
];
I've done this to keep the file clean. The collection endpoint gets entry data and works fine, however the Events does not
Ah ok. And you’re sure that $type
in your working code is getting set to event
or whatever the section
param is set to?
Yes, however even without I should be seeing something as the fallbacks all exist
Try removing the criteria
array, and see if it works without setting any event query params.
Im using the Verbb Events plugin and trying to return all events from the CMS using this code:
However I get no entries back. If I run
$events = Event::find()->type($type)->all();
this does return information so wondering why the above doesn't work?