mariyo / kohana-pagination

此包最新版本(v3.3.1.x-dev)没有提供许可证信息。

Kohana模块,用于快速轻松地管理分页

安装: 8

依赖者: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 107

类型: kohana-module

v3.3.1.x-dev 2016-02-15 10:39 UTC

This package is not auto-updated.

Last update: 2024-09-20 18:28:48 UTC


README

基本上是修改以支持Kohana 3.3和3.2,因此有一些注意事项

  • 添加了请求、路由和路由参数的依赖注入
  • 默认使用当前请求而不是初始请求(在3.2及之前直接使用$_GET)
  • 已删除URL::query(),添加Pagination::query()代替(支持HMVC)
  • 添加了限制渲染HTML模板中链接的功能。

使用示例

    //first calc average count
    $count     = $count_sql->count_all();

    //you can change items_per_page
    $num = 10;
    //you can configure routes and custom routes params
    $pagination = Pagination::factory(array(
                        'total_items'    => $count,
                        'items_per_page' => $num,
    //                    'current_page'   => Request::current()->param("page"),
                            )
                    )
                    ->route_params(array(
                'directory'  => Request::current()->directory(),
                'controller' => Request::current()->controller(),
                'action'     => Request::current()->action(),
                "id"         => $date,
                "id2"        => $date2,
                    )
            );

    //now select from your DB using calculated offset
    $logs = $logs_sql->order_by("id", "DESC")
                    ->limit($pagination->items_per_page)
                    ->offset($pagination->offset)
                    ->group_by("id")
                    ->find_all()->as_array();

    //and finally set view variables
    $this->content = View::factory("admin/log/asb/main.tpl")
            ->set("logs", $logs)
            ->set('pagination', $pagination);

变量 $pagination 将自动从tpl HTML转换为渲染结果。

本版本增加了新的配置功能!

配置示例

    return array(
        // Application defaults
        'default' => array(
            // source: "query_string" or "route"
            'current_page'      => array('source' => 'query_string',
                                         'key'    => 'page'),
            'total_items'       => 0,
            'items_per_page'    => 10,
            'view'              => 'pagination/limited',
            'auto_hide'         => TRUE,
            'first_page_in_url' => FALSE,

            //NEW! Use limited template.
            'max_left_pages'    => 10,
            'max_right_pages'   => 10,
        ),
    );

在pagination/view文件夹中添加了限制模板,可以根据配置变量限制左右页面的链接数量。