-
Notifications
You must be signed in to change notification settings - Fork 146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added example for extra key in ApiListener Action #657
base: master
Are you sure you want to change the base?
Conversation
I thought the documentation could get a bit improved here with an example of how exactly add an extra key to response, as up for today I never really figured it out and even then it took me some trying ;)
docs/listeners/api.rst
Outdated
.. code-block:: php | ||
|
||
<?php | ||
class MyAction extends BaseAction |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of an example using a custom action class, an example which uses $this->Crud->action()->setConfig()
would be more suitable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean like, so?
class SomeController extends AppController {
public function initialize() {
$this->Crud->setConfig([
'serialize' => [
'my_extra_data'
],
'api' => [
'success' => [
'data' => [
'entity' => [],
'my_extra_data'
]
]
]
]);
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, though you missed the ->action()
in the call chain and it should be done in beforeFilter()
or controller's action method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Personnaly, I'm using it like this :
$this->set(compact('aggregation'));
$this->Crud->action()->setConfig('serialize.aggregation', 'aggregation');
I've update the code example to searilize variable in beforeFilter ans also added the method of doing that in a controller action, thanks to @irongomme.
Why did those checks fail? |
I thought the documentation could get a bit improved here with an example of how exactly add an extra key to response, as up for today I never really figured it out and even then it took me some trying ;)