tscms / pagination

关于该软件包最新版本(dev-master)的许可证信息不可用。

Kohana模块,用于快速便捷地管理分页

维护者

详细信息

github.com/tscms/pagination

源代码

安装: 15

依赖者: 0

建议者: 0

安全性: 0

星标: 0

关注者: 2

分支: 107

类型:kohana-module

dev-master 2015-09-20 20:59 UTC

This package is not auto-updated.

Last update: 2024-09-18 10:37:41 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,可以通过配置变量限制左右分页链接的数量。