Qeephp content Paging

Source: Internet
Author: User

When there are many items in the list, we can display the data by page.

Structure of the user table

 

Now we want to display the user in the form of a list. Obviously, it is impossible to display the query results on one page. In this case, we need to display the results by page. First, we need to control the page by page. copy php to the control file of the project, and then enter the following code in the controller:

01
Function actionCusList ()
02
{
03
$ Cus_info = User: find ();
04
// Obtain the current page
05
$ Page = intval ($ this-> _ context-> page );
06
$ Page <1? 1: $ page;
07
// Set the number of entries displayed on each page
08
$ Page_size = 10;
09

10
// Search for users based on conditions
11
If ($ id = $ this-> _ context-> get ('cuz _ 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
// Rendering View
32
$ This-> _ view ['url _ args '] = $ this-> _ context-> get ();
33
$ This-> _ view ['pagination'] = $ cus_info-> getPagination ();
34
$ This-> _ view ['scs'] = $ SCUs;
35
}
One of the items in this Code is to search for users by conditions. We can design a form on the foreground to allow users to enter specific conditions to search for users. The Code is as follows:

01
<Div class = "pt10">
02
<A href = "javascript:;" onclick = "javascript: $ (this ). parent (). next ('div '). toggle (); "title =" search & gt; "> Search & gt;
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> & nbsp; </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
& Lt; th width = "5%" & gt; Action & lt;/th & gt;
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 $ cuz ['email '];?> </Td>
58
<Td> <? Php echo $ cus ['signature'] ['name'];?> </Td>
59
<Td> <? Php echo $ cus ['last _ login_date '];?> </Td>
60
<Td>
61
<A href = "<? Php echo url ('cuz/cusdetail ', array ('id' => $ cuz ['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>
The key code for paging is:

1
<? Php echo $ this-> _ control ('page', 'P', array ('pagination' => $ pagination, 'url _ args '=> $ url_args);?>
Display result

 


Author: frylan

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.