wecenter学习笔记-分页组件的实现

字数 153阅读 135

该文是wecenter学习笔记的一部分

分页组件的实现

分页是列表展示常见的需求,因而wecenter提供了一个基础的分页工具类 core_pagination

根据以下基本参数

  • base_url
  • total_rows
  • per_page

生成一个分页导航视图(html)

使用

TPL::assign('pagination', AWS_APP::pagination()->initialize(array(
                'base_url' => get_js_url('/admin/approval/list/type-' . $_GET['type']),
                'total_rows' => $found_rows,
                'per_page' => $this->per_page
            ))->create_links());
<span class="pull-right mod-page"><?php echo $this->pagination; ?></span>

实现

自定义参数

views/default/config/pagination.php

$config = array(
    'first_link' => '<<',
    'next_link' => '>',
    'prev_link' => '<',
    'last_link' => '>>',
    'uri_segment' => 3,
    'full_tag_open' => '<div class="page-control"><ul class="pagination pull-right">',
    'full_tag_close' => '</ul></div>',
    'first_tag_open' => '<li>',
    'first_tag_close' => '</li>',
    'last_tag_open' => '<li>',
    'last_tag_close' => '</li>',
    'first_url' => '', // Alternative URL for the First Page.
    'cur_tag_open' => '<li class="active"><a href="javascript:;">',
    'cur_tag_close' => '</a></li>',
    'next_tag_open' => '<li>',
    'next_tag_close' => '</li>',
    'prev_tag_open' => '<li>',
    'prev_tag_close' => '</li>',
    'num_tag_open' => '<li>',
    'num_tag_close' => '</li>',
    'display_pages' => TRUE,
    'anchor_class' => '',
    'num_links' => 3
);

具体逻辑参照

system/core/pagination.php#create_links

基本思路

  • 根据总记录数算出总页数
  • 根据当前页和总页数和配置的标签生成分页html代码

验证码管理 ←o→ 表单防CSRF(Cross-site request forgery)的实现

推荐阅读更多精彩内容