When there are many items in the list, we can display the data by page. The structure of the user table is now displayed as a list. Obviously, it is impossible to display the query results on a single page. in this case, you must display the results by page. copy php to project... syntaxHighlighter. all ();
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
02
"> Search>
03
04
05
06
07
Close
08
34
35
36
37
_ Control ('page', 'P', array ('pagination' => $ pagination, 'URL _ args '=> $ url_args);?>
38
39
40
41
42
| Cust. ID | 43
First Name | 44
Last Name | 45
Email Address | 46
Program | 47
Last Login | 48
Action | 49
50
51 52
53
54
| | 55
| 56
| 57
| 58
| 59
| 60
61 $ Cus ['id'])?> "Title =" View "> View 62
| 63
64
65 66
67
68
_ Control ('page', 'P', array ('pagination' => $ pagination, 'URL _ args '=> $ url_args);?>
69
The key code for paging is:
1
_ Control ('page', 'P', array ('pagination' => $ pagination, 'URL _ args '=> $ url_args);?>
Display result
Author: frylan