Closed thaoms closed 6 years ago
Params in a querystring only exist in the context of a web browser/request, not at the console. If you don't want that code to run in the context of a console request, you can do something like:
'query' => !Craft::$app->getRequest()->getIsConsoleRequest() ? 'title:' . Craft::$app->getRequest()->getParam('q') : null,
Rather than modify your query
logic, you could leave that as-is, but place all of your endpoint config array inside an anonymous function. (See Dynamic URL Patterns and Endpoint Configurations.)
'endpoint-url-pattern' => function() {
return [
'criteria' => [
'section' => 'productions',
'limit' => 10,
'search' => [
'query' => 'title:' . Craft::$app->getRequest()->getParam('q'),
'subLeft' => true,
'subRight' => true,
],
],
// ...
];
},
That way, your endpoint config will only be generated when the endpoint is actually requested, rather than on every web & console request.
This seems to be a common problem, maybe you could add a note to the readme? Or have both example endpoints return a function.
@carlcs Yeah good idea, now all endpoint config examples use a function.
I'm fetching some data before using the element api:
But when using the Craft cli with
./craft
I get this error:Not really sure where to post this issue.