Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gringlas
Copy link
Contributor

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 ;)

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 ;)
.. code-block:: php

<?php
class MyAction extends BaseAction
Copy link
Member

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.

Copy link
Contributor Author

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'
                    ]
                ]
            ]
        ]);
}

Copy link
Member

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.

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.
@gringlas
Copy link
Contributor Author

Why did those checks fail?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants