Paginate数组(不是来自DB)cakePHP

时间:2012-09-05 06:05:54

标签: cakephp cakephp-2.0 cakephp-2.1 paginate cakephp-2.2

在控制器中,我从网络服务$news = json_decode(@file_get_contents($submenu), true);获取一系列新闻,我需要将此数组分页为每页6条新闻。我的数组的结构:

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()
    )
         .................
)

尝试使用CakePHP文档中显示的默认分页方法,但没有运气。感谢您的建议

1 个答案:

答案 0 :(得分:1)

您可以copy cake/Controller/Component/PaginatorComponent.phpapp/Controller/Component/PaginatorComponent.php,然后覆盖其中的分页功能。 通过简单的更改,您就拥有了数组分页器。