搜索
首页php教程php手册qeephp内容分页

qeephp内容分页

Jun 13, 2016 am 10:50 AM
use内容分页列出可以我们数据显示查找进行

当列出查找的内容有很多条的时候我们可以将数据进行分页显示。

user表的结构如图:

 

现在要将用户以列表的形式显示,显然不可能将查询结果显示在一页当中,此时要将结果分页显示,首先将分页控件page.php复制到项目的control文件中,然后我们可以在控制器中输入如下代码:

01
function actionCusList()
02
{
03
    $cus_info = User::find();
04
    //获取当前是第几页
05
    $page = intval( $this->_context->page );
06
    $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


02
        Search >
03
       

04
   

05
   
06
   
35
                
36
   

37
      _control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
38
   

39
   
40
     
41
       
42
           
43
           
44
           
45
           
46
           
47
           
48
           
49
       
50
     
51
     
52
     
53
       
54
         
55
         
56
         
57
         
58
         
59
         
60
         
63
       
64
    
65
    
66
   
Cust. ID First Name Last Name Email Address Program Last Login Action

61
            View
62
         

67
   

68
      _control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
69
   

分页关键代码为:

1
_control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
显示结果如图:

 


作者:frylan

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

安全考试浏览器

安全考试浏览器

Safe Exam Browser是一个安全的浏览器环境,用于安全地进行在线考试。该软件将任何计算机变成一个安全的工作站。它控制对任何实用工具的访问,并防止学生使用未经授权的资源。

WebStorm Mac版

WebStorm Mac版

好用的JavaScript开发工具

PhpStorm Mac 版本

PhpStorm Mac 版本

最新(2018.2.1 )专业的PHP集成开发工具