Skip to content

Commit 12471b1

Browse files
committed
Add support to "serialize" option when set to true
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
1 parent 66a6843 commit 12471b1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/Controller/Component/ApiPaginationComponent.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ public function beforeRender(Event $event)
5959

6060
$subject->set($config['key'], $this->pagingInfo);
6161
$data = $subject->viewBuilder()->getOption('serialize') ?? [];
62-
$data[] = $config['key'];
63-
$subject->viewBuilder()->setOption('serialize', $data);
62+
63+
if (is_array($data)) {
64+
$data[] = $config['key'];
65+
$subject->viewBuilder()->setOption('serialize', $data);
66+
}
6467
}
6568

6669
/**

0 commit comments

Comments
 (0)