qeephp content paging_PHP tutorial

WBOY
Release: 2016-07-13 17:52:21
Original
1227 people have browsed it

When there are many items to be searched for, we can display the data in pages.

The structure of the user table is as follows:

qeephp content paging_PHP tutorial

Now we want to display users in the form of a list. Obviously it is impossible to display the query results on one page. At this time, we want to display the results in pages. First, copy the paging control page.php to the control file of the project, and then we You can enter the following code in the controller:

01
function actionCusList()
02
{
03
$cus_info = User::find();
04
//Get the current page
05
$page = intval( $this->_context->page );
06
$page 07
//Set the number displayed on each page
08
$page_size = 10;
09
                                                                                                         10
//Find users by conditions
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
//Render view
32
$this->_view['url_args'] = $this->_context->get();
33
$this->_view['pagination'] = $cus_info->getPagination();
34
$this->_view['cus'] = $cus;
35
}
One part of this code is to find users based on conditions. We can design a form at the front end to allow users to enter specific conditions to find users. The code is as follows:

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));?>
显示结果如图:

 qeephp content paging_PHP tutorial


作者:frylan

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/478118.htmlTechArticle当列出查找的内容有很多条的时候我们可以将数据进行分页显示。 user表的结构如图: 现在要将用户以列表的形式显示,显然不可能将查询...
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!