Paginate array (not from DB) cakePHP
-
30-06-2021 - |
Pregunta
In controller I'm getting array of news from web-service $news = json_decode(@file_get_contents($submenu), true);
and I need to paginate this array to 6 news per page. My array's structure:
array(
(int) 0 => array(
'id' => '716',
'city_id' => null,
'language' => 'lit',
'header' => 'Lorem ipsum dolor sit amet.',
'description' => '<p>Sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna.',
'short_description_img' => '',
'autor' => 'Avio',
'friendly_link' => 'Lorem_ipsum_dolor_sit_amet_1346393036',
'created' => '2012-08-31 09:03:56',
'general_tag' => array(
'id' => null,
'agency_id' => null,
'project_id' => null,
'active' => null,
'language' => null,
'title' => null,
'friendly_link' => null,
'healthcare_trip_tag' => null,
'created' => null
),
'tags' => array()
)
(int) 1 => array(
'id' => '717',
'city_id' => null,
'language' => 'lit',
'header' => 'Lorem ipsum dolor sit amet.',
'description' => '<p>Sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna.',
'short_description_img' => '',
'autor' => 'Avio',
'friendly_link' => 'Lorem_ipsum_dolor_sit_amet_1346393036',
'created' => '2012-08-31 09:03:56',
'general_tag' => array(
'id' => null,
'agency_id' => null,
'project_id' => null,
'active' => null,
'language' => null,
'title' => null,
'friendly_link' => null,
'healthcare_trip_tag' => null,
'created' => null
),
'tags' => array()
)
.................
)
Tried default pagination method as shown in CakePHP documentation but no luck. Thanks for advices
Solución
you can copy cake/Controller/Component/PaginatorComponent.php
to app/Controller/Component/PaginatorComponent.php
, then override the paginate function in it.
By Simple changes you have array paginator.
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow