网上办理银行卡可以办理网上办理银行卡银行卡吗?

CI框架源码解析十九之分页类文件Pagination.php - 博客频道 - CSDN.NET
让编程改变世界
让编程改变世界、改变生活、改变自己
分类:CodeIgniter
& & & & CodeIgniter 的分页类非常容易使用,而且它 100% 可定制,可以通过动态的参数,也可以通过保存在配置文件中的参数。如果你还不熟悉 &分页& 这个词,它指的是用于你在页面之间进行导航的链接。像下面这样:
<< First&&&&1&2&3&4&5&&&&Last >>
举个例子说明如何在你的控制器方法中创建分页:
Ⅰ 在构造函数中引入分页类: public function __construct(){
parent::__construct();
$this-&load-&library(&#39;form_validation&#39;);
$this-&load-&model(&#39;goodstype_model&#39;);
$this-&load-&library(&#39;pagination&#39;);//引入分页类
Ⅱ 设置配置参数,然后初始化调用输出:
public function index($offset = &#39;&#39;)
//配置分页信息
$config[&#39;base_url&#39;] = site_url(&#39;admin/goodstype/index&#39;);
//获取数据库总条数
$config[&#39;total_rows&#39;] = $this-&goodstype_model-&count_goodstype();
//每页显示条数
$config[&#39;per_page&#39;] = 2;
//页码参数位置
$config[&#39;uri_segment&#39;] = 4;
//自定义分页连接
$config[&#39;first_link&#39;] = &#39;首页&#39;;
$config[&#39;last_link&#39;] = &#39;尾页&#39;;
$config[&#39;prev_link&#39;] = &#39;上一页&#39;;
$config[&#39;next_link&#39;] = &#39;下一页&#39;;
//初始化分类页
$this-&pagination-&initialize($config);
//生成分页信息
//可以输出查看结果是一串html字符串
$data[&#39;pageinfo&#39;] = $this-&pagination-&create_links();
$limit = $config[&#39;per_page&#39;];
$data[&#39;goodstypes&#39;] = $this-&goodstype_model-&list_goodstype($limit,$offset);
$this-&load-&view(&#39;goods_type_list.html&#39;,$data);
& & & & CI框架的分页类非常的好用,可以让我们随心所欲的去修改定制。但是在这里要说的是,CI框架的分页功能仅仅只是提供一个显示功能,不存在任何和数据库进行交互的作用,它所显示的仅仅只是一个连接,其具体的数据查询功能,数据显示功能还是要我们自己在模型中进行编写,这是CI框架的分页类和其他框架所不同的地方。大家要注意。好了,本篇就说这么多,其实分页类的代码功能还是非常简单明了的,只要稍微的看一篇就能明白其具体的实现过程。
& & & &&最后贴一下CI框架整个分页类Pagination.php文件的源代码(注释版):
* =======================================
* Created by Pocket Knife Technology.
* User: ZhiHua_W
* Time: 下午 4:14
* Project: CodeIgniter框架—源码分析
* Power: Analysis for Pagination.php
* =======================================
defined(&#39;BASEPATH&#39;) OR exit(&#39;No direct script access allowed&#39;);
* 用于生成分页连接
class CI_Pagination
//每次访问的url地址
protected $base_url = &#39;&#39;;
//给路径添加一个自定义前缀,前缀位于偏移段的前面
protected $prefix = &#39;&#39;;
//给路径添加一个自定义后缀,后缀位于偏移段的后面。
protected $suffix = &#39;&#39;;
//这个数字表示你需要做分页的数据的总行数。通常这个数值是你查询数据库得到的数据总量。
protected $total_rows = 0;
//放在你当前页码的前面和后面的“数字”链接的数量。
//比方说值为 2 就会在每一边放置两个数字链接,就像此页顶端的示例链接那样。
protected $num_links = 2;
//这个数字表示每个页面中希望展示的数量,在上面的那个例子中,每页显示 10 个项目。
public $per_page = 10;
public $cur_page = 0;
//默认分页的 URL 中显示的是你当前正在从哪条记录开始分页,
//如果你希望显示实际的页数,将该参数设置为 TRUE 。
protected $use_page_numbers = FALSE;
//首页,左边第一个链接显示的文本,如果你不想显示该链接,将其设置为 FALSE 。
protected $first_link = &#39;&#39;;
//分页方法自动检测你 URI 的哪一段包含页数,如果你的情况不一样,你可以明确指定它
protected $uri_segment = 4;
//起始标签放在所有结果的左侧。
//你可以在标签里面写任意的样式等等
//不过样式最好的还是采取分离的方式写最好,仅在这边添加不同的class就可以了
protected $full_tag_open = &#39;&ul class=&pagination pagination-sm&&&#39;;
//结束标签放在所有结果的右侧。
protected $full_tag_close = &#39;&/ul&&#39;;
//第一个链接的起始标签。
protected $first_tag_open = &#39;&li&&#39;;
//第一个链接的结束标签。
protected $first_tag_close = &#39;&/li&&#39;;
//最后一个链接的起始标签。
protected $last_tag_open = &#39;&li&&#39;;
//最后一个链接的结束标签。
protected $last_tag_close = &#39;&/li&&#39;;
protected $first_url = &#39;&#39;;
//当前页链接的起始标签。
protected $cur_tag_open = &#39;&li class=&active&&&a href=&javascript:;&&&#39;;
//当前页链接的结束标签。
protected $cur_tag_close = &#39;&/a&&/li&&#39;;
//下一页链接的起始标签。
protected $next_tag_open = &#39;&li&&#39;;
//下一页链接的结束标签。
protected $next_tag_close = &#39;&/li&&#39;;
//上一页链接的起始标签。
protected $prev_tag_open = &#39;&li&&#39;;
//上一页链接的结束标签。
protected $prev_tag_close = &#39;&/li&&#39;;
//数字链接的起始标签。
protected $num_tag_open = &#39;&li&&#39;;
//数字链接的结束标签。
protected $num_tag_close = &#39;&/li&&#39;;
//默认情况下,分页类假设你使用 URI 段 ,并像这样构造你的链接:
///index.php/test/page/20
protected $page_query_string = FALSE;
protected $query_string_segment = &#39;per_page&#39;;
//如果你不想显示数字链接(例如你只想显示上一页和下一页链接),你可以通过下面的代码来阻止它显示
protected $display_pages = TRUE;
//如果你想为分页类生成的每个链接添加额外的属性
protected $_attributes = &#39;&#39;;
//连接类型
protected $_link_types = array();
//默认情况下你的查询字符串参数会被忽略,将这个参数设置为 TRUE ,
//将会将查询字符串参数添加到 URI 分段的后面以及 URL 后缀的前面
protected $reuse_query_string = FALSE;
//当该参数设置为 TRUE 时,会使用 application/config/config.php
//配置文件中定义的 $config[&#39;url_suffix&#39;] 参数 重写 $config[&#39;suffix&#39;] 的值
protected $use_global_url_suffix = FALSE;
//给数字增加属性
protected $data_page_attr = &#39;data-ci-pagination-page&#39;;
//CI Singleton
protected $CI;
* 构造函数-&处理数据
* 在使用加载此类之后,设置一些数据例如:
* //配置分页信息
* $config[&#39;base_url&#39;] = site_url(&#39;admin/goodstype/index&#39;);
* $config[&#39;total_rows&#39;] = $this-&goodstype_model-&count_goodstype();
* $config[&#39;per_page&#39;] = 2;
* $config[&#39;uri_segment&#39;] = 4;
* //自定义分页连接
* $config[&#39;first_link&#39;] = &#39;首页&#39;;
* $config[&#39;last_link&#39;] = &#39;尾页&#39;;
* $config[&#39;prev_link&#39;] = &#39;上一页&#39;;
* $config[&#39;next_link&#39;] = &#39;下一页&#39;;
public function __construct($params = array())
$this-&CI = &get_instance();
$this-&CI-&load-&language(&#39;pagination&#39;);
foreach (array(&#39;first_link&#39;, &#39;next_link&#39;, &#39;prev_link&#39;, &#39;last_link&#39;) as $key) {
if (($val = $this-&CI-&lang-&line(&#39;pagination_&#39; . $key)) !== FALSE) {
$this-&$key = $
$this-&initialize($params);
log_message(&#39;info&#39;, &#39;Pagination Class Initialized&#39;);
* 功能同样是处理参数
public function initialize(array $params = array())
isset($params[&#39;attributes&#39;]) OR $params[&#39;attributes&#39;] = array();
if (is_array($params[&#39;attributes&#39;])) {
$this-&_parse_attributes($params[&#39;attributes&#39;]);
unset($params[&#39;attributes&#39;]);
if (isset($params[&#39;anchor_class&#39;])) {
empty($params[&#39;anchor_class&#39;]) OR $attributes[&#39;class&#39;] = $params[&#39;anchor_class&#39;];
unset($params[&#39;anchor_class&#39;]);
foreach ($params as $key =& $val) {
if (property_exists($this, $key)) {
$this-&$key = $
if ($this-&CI-&config-&item(&#39;enable_query_strings&#39;) === TRUE) {
$this-&page_query_string = TRUE;
if ($this-&use_global_url_suffix === TRUE) {
$this-&suffix = $this-&CI-&config-&item(&#39;url_suffix&#39;);
* 创建分页连接
* 这个就是我们需要条用到的了,这个函数最后会返回一串html代码,
* 而我们仅将这段html代码在前台显示即可。
* CI框架的分页类和TP框架的分页类有这明显的差别。
* CI仅是提供分页显示,并不提供其和数据库交互的功能。
* 这也就让我们可以对其进行100%的定制。
* 非常的小巧方便。
public function create_links()
//我们在初始化的时候必须要有数据总条数和每页显示条数
if ($this-&total_rows == 0 OR $this-&per_page == 0) {
return &#39;&#39;;
//计算页面总数
$num_pages = (int)ceil($this-&total_rows / $this-&per_page);
//如果只有一页,则直接然会空字符串
if ($num_pages === 1) {
return &#39;&#39;;
//检查用户定义的链接数
$this-&num_links = (int)$this-&num_
if ($this-&num_links & 0) {
show_error(&#39;Your number of links must be a non-negative number.&#39;);
//保留任何现有的查询字符串项目。
//注:与任何其他查询字符串选项无关。
if ($this-&reuse_query_string === TRUE) {
$get = $this-&CI-&input-&get();
unset($get[&#39;c&#39;], $get[&#39;m&#39;], $get[$this-&query_string_segment]);
$get = array();
//处理我们的基础网址和第一个网址
$base_url = trim($this-&base_url);
$first_url = $this-&first_
$query_string = &#39;&#39;;
$query_string_sep = (strpos($base_url, &#39;?&#39;) === FALSE) ? &#39;?&#39; : &#39;&&#39;;
if ($this-&page_query_string === TRUE) {
//如果自定义first_url还没有被确定,我们会从base_url创建一个网页,但没有项目。
if ($first_url === &#39;&#39;) {
$first_url = $base_
if (!empty($get)) {
$first_url .= $query_string_sep . http_build_query($get);
$base_url .= $query_string_sep . http_build_query(array_merge($get, array($this-&query_string_segment =& &#39;&#39;)));
//生成我们保存的查询字符串,以在页面号以后追加。
if (!empty($get)) {
$query_string = $query_string_sep . http_build_query($get);
$this-&suffix .= $query_
if ($this-&reuse_query_string === TRUE && ($base_query_pos = strpos($base_url, &#39;?&#39;)) !== FALSE) {
$base_url = substr($base_url, 0, $base_query_pos);
if ($first_url === &#39;&#39;) {
$first_url = $base_url . $query_
$base_url = rtrim($base_url, &#39;/&#39;) . &#39;/&#39;;
//确定当前页号。
$base_page = ($this-&use_page_numbers) ? 1 : 0;
//判断我们是否使用查询字符串
if ($this-&page_query_string === TRUE) {
$this-&cur_page = $this-&CI-&input-&get($this-&query_string_segment);
} elseif (empty($this-&cur_page)) {
//如果uri_segment一个没有被定义,默认的最后一个段的数字。
if ($this-&uri_segment === 0) {
$this-&uri_segment = count($this-&CI-&uri-&segment_array());
$this-&cur_page = $this-&CI-&uri-&segment($this-&uri_segment);
//从该段中删除任何指定的前缀/后缀。
if ($this-&prefix !== &#39;&#39; OR $this-&suffix !== &#39;&#39;) {
$this-&cur_page = str_replace(array($this-&prefix, $this-&suffix), &#39;&#39;, $this-&cur_page);
$this-&cur_page = (string)$this-&cur_
if (!ctype_digit($this-&cur_page) OR ($this-&use_page_numbers && (int)$this-&cur_page === 0)) {
$this-&cur_page = $base_
//确保我们使用的是比较后的整数。
$this-&cur_page = (int)$this-&cur_
if ($this-&use_page_numbers) {
if ($this-&cur_page & $num_pages) {
$this-&cur_page = $num_
} elseif ($this-&cur_page & $this-&total_rows) {
$this-&cur_page = ($num_pages - 1) * $this-&per_
$uri_page_number = $this-&cur_
//如果我们使用的是偏移量而不是页面号,将它转换为一个页面号,
//这样我们就可以生成周围的数字链接了。
if (!$this-&use_page_numbers) {
$this-&cur_page = (int)floor(($this-&cur_page / $this-&per_page) + 1);
//计算开始和结束的数字。这些决定开始和结束数字链接的数量。
$start = (($this-&cur_page - $this-&num_links) & 0) ? $this-&cur_page - ($this-&num_links - 1) : 1;
$end = (($this-&cur_page + $this-&num_links) & $num_pages) ? $this-&cur_page + $this-&num_links : $num_
//这个变量就是最后返回的字符串
$output = &#39;&#39;;
//生成首页链接
if ($this-&first_link !== FALSE && $this-&cur_page & ($this-&num_links + 1 + !$this-&num_links)) {
//为html代码添加设置的js属性
$attributes = sprintf(&#39;%s %s=&%d&&#39;, $this-&_attributes, $this-&data_page_attr, 1);
$output .= $this-&first_tag_open . &#39;&a href=&&#39; . $first_url . &#39;&&#39; . $attributes . $this-&_attr_rel(&#39;start&#39;) . &#39;&&#39; . $this-&first_link . &#39;&/a&&#39; . $this-&first_tag_
// 生成上一页链接
//我个人感觉生成上一页的这个连接没用,我们本身已经有了和相邻的页面连接
//故而上一页和下一页在我看来没有用处,我一般都是将此段和下一页都注视掉
if ($this-&prev_link !== FALSE && $this-&cur_page !== 1) {
$i = ($this-&use_page_numbers) ? $uri_page_number - 1 : $uri_page_number - $this-&per_
$attributes = sprintf(&#39;%s %s=&%d&&#39;, $this-&_attributes, $this-&data_page_attr, ($this-&cur_page - 1));
if ($i === $base_page) {
$output .= $this-&prev_tag_open . &#39;&a href=&&#39; . $first_url . &#39;&&#39; . $attributes . $this-&_attr_rel(&#39;prev&#39;) . &#39;&&#39; . $this-&prev_link . &#39;&/a&&#39; . $this-&prev_tag_
$append = $this-&prefix . $i . $this-&
$output .= $this-&prev_tag_open . &#39;&a href=&&#39; . $base_url . $append . &#39;&&#39; . $attributes . $this-&_attr_rel(&#39;prev&#39;) . &#39;&&#39; . $this-&prev_link . &#39;&/a&&#39; . $this-&prev_tag_
//渲染页面
//也就是将你设置的所需要添加的html标签代码,属性,都给加上
if ($this-&display_pages !== FALSE) {
for ($loop = $start - 1; $loop &= $ $loop++) {
$i = ($this-&use_page_numbers) ? $loop : ($loop * $this-&per_page) - $this-&per_
$attributes = sprintf(&#39;%s %s=&%d&&#39;, $this-&_attributes, $this-&data_page_attr, $loop);
if ($i &= $base_page) {
if ($this-&cur_page === $loop) {
$output .= $this-&cur_tag_open . $loop . $this-&cur_tag_
} elseif ($i === $base_page) {
$output .= $this-&num_tag_open . &#39;&a href=&&#39; . $first_url . &#39;&&#39; . $attributes . $this-&_attr_rel(&#39;start&#39;) . &#39;&&#39; . $loop . &#39;&/a&&#39; . $this-&num_tag_
$append = $this-&prefix . $i . $this-&
$output .= $this-&num_tag_open . &#39;&a href=&&#39; . $base_url . $append . &#39;&&#39; . $attributes . &#39;&&#39; . $loop . &#39;&/a&&#39; . $this-&num_tag_
//生成下一页连接
if ($this-&next_link !== FALSE && $this-&cur_page & $num_pages) {
$i = ($this-&use_page_numbers) ? $this-&cur_page + 1 : $this-&cur_page * $this-&per_
$attributes = sprintf(&#39;%s %s=&%d&&#39;, $this-&_attributes, $this-&data_page_attr, $this-&cur_page + 1);
$output .= $this-&next_tag_open . &#39;&a href=&&#39; . $base_url . $this-&prefix . $i . $this-&suffix . &#39;&&#39; . $attributes . $this-&_attr_rel(&#39;next&#39;) . &#39;&&#39; . $this-&next_link . &#39;&/a&&#39; . $this-&next_tag_
//生成最后一页(尾页)连接
if ($this-&last_link !== FALSE && ($this-&cur_page + $this-&num_links + !$this-&num_links) & $num_pages) {
$i = ($this-&use_page_numbers) ? $num_pages : ($num_pages * $this-&per_page) - $this-&per_
$attributes = sprintf(&#39;%s %s=&%d&&#39;, $this-&_attributes, $this-&data_page_attr, $num_pages);
$output .= $this-&last_tag_open . &#39;&a href=&&#39; . $base_url . $this-&prefix . $i . $this-&suffix . &#39;&&#39; . $attributes . &#39;&&#39; . $this-&last_link . &#39;&/a&&#39; . $this-&last_tag_
//将生成的结果html代码字符串进行处理
$output = preg_replace(&#39;#([^:&])//+#&#39;, &#39;\\1/&#39;, $output);
//如果存在添加封装HTML
return $this-&full_tag_open . $output . $this-&full_tag_
* 解析属性
protected function _parse_attributes($attributes)
isset($attributes[&#39;rel&#39;]) OR $attributes[&#39;rel&#39;] = TRUE;
$this-&_link_types = ($attributes[&#39;rel&#39;]) ? array(&#39;start&#39; =& &#39;start&#39;, &#39;prev&#39; =& &#39;prev&#39;, &#39;next&#39; =& &#39;next&#39;) : array();
unset($attributes[&#39;rel&#39;]);
$this-&_attributes = &#39;&#39;;
foreach ($attributes as $key =& $value) {
$this-&_attributes .= &#39; &#39; . $key . &#39;=&&#39; . $value . &#39;&&#39;;
* 添加“关系”属性
protected function _attr_rel($type)
if (isset($this-&_link_types[$type])) {
unset($this-&_link_types[$type]);
return &#39; rel=&&#39; . $type . &#39;&&#39;;
return &#39;&#39;;
注:其中有部分代码标签是我自己添加的,其变量表示和源码有点不一样,大家看的时候要注意!后面再写这些博文,一般就没有什么规律的,一般都是用到那个酒吧那个写一遍。
排名:千里之外
(19)(4)(23)(5)(0)(2)(4)(1)经检测你所在的网络可能存在爬虫,因资源限制,我们只能拒绝你的请求。
如果你是推酷的用户,可以以继续访问使用。
如有疑问,可将IP信息发送到
请求解封。CI框架的分页怎么用(含代码写给新手)
这是我业务方面的一些代码分享给大家:
这里是controller里面的两个方法:
//分页设置
function page_config($count, $add) {
$config [&#39;base_url&#39;] = $ //设置基地址
$config [&#39;uri_segment&#39;] = 3; //设置url上第几段用于传递分页器的偏移量
$config [&#39;total_rows&#39;] = $
$config [&#39;per_page&#39;] = 10; //每页显示的数据数量
//$config [&#39;first_link&#39;] = &#39;首页&#39;;
//$config [&#39;last_link&#39;] = &#39;末页&#39;;
$config [&#39;next_link&#39;] = &#39;下一页&&#39;;
$config [&#39;prev_link&#39;] = &#39;&上一页&#39;;
} //业务签单列表
function market_list() {
$data [&#39;action_market&#39;] = $this-&user_action()-&action_
$this-&session ();
$add = &#39;market/market_list&#39;;
$count = $this-&db-&count_all ( &#39;market_sig&#39; ); //取数量
$config = $this-&page_config ( $count, $add );
$this-&pagination-&initialize ( $config ); //设置完成分页器
$this-&load-&library ( &#39;table&#39; ); //加载表格类
$data [&#39;list&#39;] = $this-&Mmarket-&market_sig ( $config [&#39;per_page&#39;], $this-&uri-&segment ( 3 ) ); //这里看market的model类
$this-&load-&view ( &#39;market/market_list&#39;, $data );
下面是model类里面的方法:
function market_sig($n,$o) {
if($o==&#39;&#39;){$o=0;}
$result = $this-&db-&query ( &select * from market_sig where del!=0 order by sig_time desc limit $o,$n& );
$re = $result-&result ();
view里面只要这样写就可以了:
pagination-&create_links(); ?&
代码供您参考。
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'CI中的分页类的使用
& 首先,要查询数据库,确定一共有多少条数据
$this-&load-&model('test_model');
$user=$this-&test_model-&user_select_all();
$pageall=count($user);//总条数
& &$pagenum=20;//每页显示的条数
& 其次,进行config的配置
$config['total_rows']=$
&&&$config['per_page']=$
&$config['num_links']=3;//定义当前页面的前后各有几个数字链接
&&&$config['base_url']="";
&&&$config['use_page_numbers']=//URL中的数字显示第几页,否则,显示到达第几条
& 最后,载入分页类,并调用
&$this-&load-&library("pagination");//载入
&&&$this-&pagination-&initialize($config);//初始化配置
$this-&pagination-&create_links();//显示&1
2&3 4.....&这样的页数选择
& &$id=$id?$id:1;
& &$start=($id-1)*$
&$list=$this-&test_model-&user_select_limit($start,$pagenum);//每一页的内容
&&&var_dump($list);
以上网友发言只代表其个人观点,不代表新浪网的观点或立场。}

我要回帖

更多关于 网上办银行卡 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信