Skip to content

Commit

Permalink
Add support to "serialize" option when set to true
Browse files Browse the repository at this point in the history
When the viewBuilder's "serialize" option is set to true, all the view
variables are serialized. Some controllers classes can use this feature
in your 'initialize' methods to avoid set up this option in all your
actions.

[1] - https://api.cakephp.org/4.2/class-Cake.View.JsonView.html
[2] - https://api.cakephp.org/4.2/class-Cake.View.XmlView.html
  • Loading branch information
LukeC8 committed May 6, 2021
1 parent 66a6843 commit 12471b1
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/Controller/Component/ApiPaginationComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,11 @@ public function beforeRender(Event $event)

$subject->set($config['key'], $this->pagingInfo);
$data = $subject->viewBuilder()->getOption('serialize') ?? [];
$data[] = $config['key'];
$subject->viewBuilder()->setOption('serialize', $data);

if (is_array($data)) {
$data[] = $config['key'];
$subject->viewBuilder()->setOption('serialize', $data);
}
}

/**
Expand Down

0 comments on commit 12471b1

Please sign in to comment.