Fuel PHP框架中的分页实现

来源:互联网 发布:mac terminal 有趣 编辑:程序博客网 时间:2024/04/30 05:59

分页类 分页类安装起来非常简单,主要用来显示你的所有纪录 如何使用分页 一个分页类简单的例子,通过set_config方法就可以进行配置,在控制器中可以使用这样的代码: $config = array ( pagination_url = http://localhost/fuel/welcome/index/ , total_ite

分页类

分页类安装起来非常简单,主要用来显示你的所有纪录

如何使用分页

一个分页类简单的例子,通过set_config方法就可以进行配置,在控制器中可以使用这样的代码:

$config = array(    'pagination_url' => 'http://localhost/fuel/welcome/index/',    'total_items' => 10,    'per_page' => 5,    'uri_segment' => 3,    'template' => array(        'wrapper_start' => '<div class="my-pagination"> ',        'wrapper_end' => ' </div>',    ),);// Config::set('pagination', $config); // you can use this too!Pagination::set_config($config);$data['example_data'] = DB::select('id', 'value')->from('pagination')                                                ->limit(Pagination::$per_page)                                                ->offset(Pagination::$offset)                                                ->execute()                                                ->as_array();$data['pagination'] = Pagination::create_links();$this->render('welcome/index', $data);

配置参数

 

你可以通过set_config方法或者在配置文件中设定全局的配置样式,下面是你可以定义的配置:

 

ParamTypeDefaultDescriptionpagination_urlstringNone分页地址.uri_segmentinteger
3
获取分页数的地址参数num_linksinteger
5
分页总数.total_itemsinteger
0
纪录总数. 通常是count()查询的结果.per_pageinteger
10
每个分页显示条数.current_pageinteger
null
载入的当前分页数 如果没有给定,默认为 1.templatearray
array(...)

全局配置数组

 

下面这个是全局配置的数组

Config::set('pagination', array(    'pagination_url' => 'http://docs.fuelphp.com/',    'uri_segment' => 2,    'total_items' => 10,    'per_page' => 20,    'template' => array(        'wrapper_start' => '<div class="pagination"> ',        'wrapper_end' => ' </div>',        'page_start' => '<span class="page-links"> ',        'page_end' => ' </span>',        'previous_start' => '<span class="previous"> ',        'previous_end' => ' </span>',        'previous_inactive_start' => ' </span class="previous-inactive">',        'previous_inactive_end' => ' </span>',        'previous_mark' => '« ',        'next_start' => '<span class="next"> ',        'next_end' => ' </span>',        'next_inactive_start' => ' </span class="next-inactive">',        'next_inactive_end' => ' </span>',        'next_mark' => ' »',        'active_start' => '<span class="active"> ',        'active_end' => ' </span>',        'regular_start' => '',        'regular_end' => '',    ),));

set_config(array $config)设定配置

create_links()创建所有分页链接

next_link($value)上一页分页

prev_link($value) 下一页分页

page_links() 显示上一页、下一页之间的分页
0 0
原创粉丝点击