search
Homephp教程php手册qeephp内容分页

qeephp内容分页

Jun 13, 2016 am 10:50 AM
usecontentPaginationlistCanWillusdatashowFindofconduct

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

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

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool