2015-05-27
当列出查找的内容有很多条的时候我们可以将数据进行分页显示。
user表的结构如图:

现在要将用户以列表的形式显示,显然不可能将查询结果显示在一页当中,此时要将结果分页显示,首先将分页控件page.php复制到项目的control文件中,然后我们可以在控制器中输入如下代码:
01
function actionCusList()
02
{
03
$cus_info = User::find();
04
//获取当前是第几页
05
$page = intval( $this->_context->page );
06
$page<1?1:$page;
07
//设置每页显示的数量
08
$page_size = 10;
09
10
//按条件查找用户
11
if($id = $this->_context->get('cus_id'))
12
$cus_info->where('id = ?', $id);
13
else
14
{
15
if($first_name = $this->_context->get('first_name'))
16
$cus_info->where('first_name = ?', $first_name);
17
18
if($last_name = $this->_context->get('last_name'))
19
$cus_info->where('last_name = ?', $last_name);
20
21
if($email = $this->_context->get('email'))
22
$cus_info->where('email = ?', $email);
23
24
if($code = $this->_context->get('code'))
25
$cus_info->where('pro_id = ?', Program::find('code = ?', $code)->getOne()->id);
26
}
27
28
$cus_info->limitPage($page, $page_size);
29
$cus = $cus_info->getAll();
30
31
//渲染视图
32
$this->_view['url_args'] = $this->_context->get();
33
$this->_view['pagination'] = $cus_info->getPagination();
34
$this->_view['cus'] = $cus;
35
}
此代码中有一处是按条件查找用户,我们可以进行前台设计一个表单让用户输入特定条件来查找用户,代码如下:
01
<div class="pt10">
02
<a href="javascript:;" onclick="javascript:$(this).parent().next('div').toggle();" title="search >">Search >
03
</a>
04
</div>
05
<!--search-->
06
<div id="searchbox" style="display: none;" class="search_box">
07
<a href="javascript:void(0);" onclick="javascript:$(this).parent().hide();" class="close2 f_r" title="close">close</a>
08
<form name="city_search_form" action="#" method="get">
09
<p>
10
<label for="">Customer ID</label>
11
<input class="text" name="cus_id" type="text">
12
</p>
13
<p>
14
<label for="">First Name</label>
15
<input name="first_name" class="text" type="text">
16
</p>
17
<p>
18
<label for="">Last Name</label>
19
<input name="last_name" class="text" type="text">
20
</p>
21
<p>
22
<label for="">Email Address</label>
23
<input name="email" class="text" type="text">
24
</p>
25
<p>
26
<label for="">Program Code</label>
27
<input name="code" class="text" type="text">
28
</p>
29
<p>
30
<label> </label>
31
<a onclick="city_search_form.submit();" title="" class="add_btn">Search</a>
32
</p>
33
</form>
34
</div>
35
36
<div class="paging pt10 txt_right">
37
<?php echo $this->_control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
38
</div>
39
<table class="pagetab mtb6" cellpadding="0" cellspacing="0" width="100%">
40
<thead>
41
<tr>
42
<th width="10%">Cust. ID</th>
43
<th width="15%">First Name</th>
44
<th width="15%">Last Name</th>
45
<th width="20%">Email Address</th>
46
<th width="10%">Program</th>
47
<th width="25%">Last Login</th>
48
<th width="5%">Action</th>
49
</tr>
50
</thead>
51
<?php foreach ($cus as $cus):; ?>
52
<tbody>
53
<tr>
54
<td><?php echo $cus['id']; ?></td>
55
<td><?php echo $cus['first_name']; ?></td>
56
<td><?php echo $cus['last_name']; ?></td>
57
<td><?php echo $cus['email']; ?></td>
58
<td><?php echo $cus['program']['name']; ?></td>
59
<td><?php echo $cus['last_login_date']; ?></td>
60
<td>
61
<a href="<?php echo url('cus/cusdetail', array('id' => $cus['id']))?>" title="View">View</a>
62
</td>
63
</tr>
64
</tbody>
65
<?php endforeach; ?>
66
</table>
67
<div class="paging pt10 txt_right">
68
<?php echo $this->_control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
69
</div>
分页关键代码为:
1
<?php echo $this->_control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
显示结果如图:

作者:frylan
1
CI框架连接数据库配置操作以及多数据库操作
09-05
2
asp 简单读取数据表并列出来 ASP如何快速从数据库读取大量数据
05-17
3
C语言关键字及其解释介绍 C语言32个关键字详解
04-05
4
C语言中sizeof是什么意思 c语言里sizeof怎样用法详解
04-26
5
PHP中的魔术方法 :__construct, __destruct , __call, __callStatic,__get, __set, __isset, __unset , __sleep,
09-05
6
将视频设置为Android手机开机动画的教程
12-11
7
PHP中的(++i)前缀自增 和 (i++)后缀自增
09-05
8
常用dos命令及语法
09-27
PHP中include和require区别之我见
2014-09-05
最简单的asp登陆界面代码 asp登陆界面源代码详细介绍
2017-04-12
php递归返回值的问题
2014-09-05
如何安装PHPstorm并配置方法教程 phpstorm安装后要进行哪些配置
2017-05-03
单片机编程好学吗?单片机初学者怎样看懂代码
2022-03-21
PHP 教程之如何使用BLOB存取图片信息实例
2014-09-05
零基础的初学者怎样学习java,或者应该先学什么?
2022-03-21
学ug编程如何快速入门?
2022-03-17
PHP数组函数array
2014-09-05
学习使用C语言/C++编程的7个步骤!超赞~
2022-03-20
球球大作战汉化版下载v19.7.1 安卓版
其它手游 170.54MB
下载
葫芦侠三楼最新破解版下载v4.4.0.6 安卓版
其它手游 34.82MB
下载
葫芦侠7楼破解版免费下载v4.4.0.6安卓最新版
其它手游 34.82MB
下载
葫芦侠八楼免费版下载v4.4.0.6安卓版
其它手游 34.82MB
下载
葫芦侠3楼破解版免费下载v4.4.0.6安卓手机版
其它手游 34.82MB
下载
像素漫斗抱歉,“八神庵”是特指游戏角色的专有名词,不存在符合要求的常用同义词近义词。下载v1.00安卓版
其它手游 206.87MB
下载
葫芦侠4楼破解版游戏修改器下载v4.4.0.6安卓免费版
其它手游 34.82MB
下载
末日餐厅安卓版下载v1.35安卓版
其它手游 73.98MB
下载葫芦侠十楼免费破解版下载v4.4.0.6安卓版
下载
葫芦侠8楼最新破解版下载v4.4.0.6安卓版
下载
猫娘乐园世界连结正版下载v1.9.1 安卓版
下载
像素漫斗全员下载v1.00安卓版
下载
葫芦侠8楼手机版下载v4.4.0.6安卓版
下载
末日餐厅正版官网入口下载v1.35安卓版
下载
我的汉克狗正版下载v26.4.1.48473 安卓版
下载
像素漫斗u鼬神最新版本下载v1.00安卓版
下载