seyfer/kohana-pagination

此包最新版本(dev-3.3/master)没有提供许可信息。

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

安装次数: 2,861

依赖者: 0

建议者: 0

安全性: 0

星标: 9

关注者: 4

分支: 107

开放问题: 0

类型:kohana-module

dev-3.3/master 2015-01-15 11:56 UTC

This package is auto-updated.

Last update: 2024-09-26 18:17:10 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文件夹中添加了受限的tpl,可以通过配置变量限制左右页码链接的数量。