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:
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
Cust. ID | First Name | Last Name | Email Address | Program | Last Login | Action |
---|---|---|---|---|---|---|
61 View 62 |
1
_control('page', 'p', array('pagination' => $pagination, 'url_args' => $url_args));?>
显示结果如图:
作者:frylan