11<?php
2+ declare (strict_types=1 );
3+
24namespace BryanCrowe \ApiPagination \Controller \Component ;
35
46use Cake \Controller \Component ;
@@ -19,7 +21,7 @@ class ApiPaginationComponent extends Component
1921 protected $ _defaultConfig = [
2022 'key ' => 'pagination ' ,
2123 'aliases ' => [],
22- 'visible ' => []
24+ 'visible ' => [],
2325 ];
2426
2527 /**
@@ -33,7 +35,7 @@ class ApiPaginationComponent extends Component
3335 * Injects the pagination info into the response if the current request is a
3436 * JSON or XML request with pagination.
3537 *
36- * @param \Cake\Event\Event $event The Controller.beforeRender event.
38+ * @param \Cake\Event\Event $event The Controller.beforeRender event.
3739 * @return void
3840 */
3941 public function beforeRender (Event $ event )
@@ -43,7 +45,7 @@ public function beforeRender(Event $event)
4345 }
4446
4547 $ subject = $ event ->getSubject ();
46- $ this ->pagingInfo = $ this ->request -> getParam ('paging ' )[$ subject ->getName ()];
48+ $ this ->pagingInfo = $ this ->getController ()-> getRequest ()-> getAttribute ('paging ' )[$ subject ->getName ()];
4749 $ config = $ this ->getConfig ();
4850
4951 if (!empty ($ config ['aliases ' ])) {
@@ -55,7 +57,9 @@ public function beforeRender(Event $event)
5557 }
5658
5759 $ subject ->set ($ config ['key ' ], $ this ->pagingInfo );
58- $ subject ->viewVars ['_serialize ' ][] = $ config ['key ' ];
60+ $ data = $ subject ->viewBuilder ()->getVar ('_serialize ' ) ?? [];
61+ $ data [] = $ config ['key ' ];
62+ $ subject ->set ('_serialize ' , $ data );
5963 }
6064
6165 /**
@@ -96,8 +100,9 @@ protected function setVisibility()
96100 */
97101 protected function isPaginatedApiRequest ()
98102 {
99- if ($ this ->request ->getParam ('paging ' ) &&
100- $ this ->request ->is (['json ' , 'xml ' ])
103+ if (
104+ $ this ->getController ()->getRequest ()->getAttribute ('paging ' )
105+ && $ this ->getController ()->getRequest ()->is (['json ' , 'xml ' ])
101106 ) {
102107 return true ;
103108 }
0 commit comments