This article mainly introduces the implementation of paging in yii2 and an example of the paging function with search. It has certain reference value and interested friends can refer to it.
1. Model configuration
The example will use three models. The article category table and article table can be generated with gii, and the last one is the search verification model. Among them, we only talk about the next joint table and search verification. No other operations are required.
1. Article table association
1 2 3 4 5 6 7 |
|
2. Search model
common/models/search/Create ArticleSearch.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
2. Use paging
Method 1
First, in the action of the controller, create the paging object and fill it with data:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
|
Secondly, in the view, the template we output is the current page and Link to the page through the paging object:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Method 2
Controller:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
View:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
|
3. Search with paging function
Create search model (done before)
Control incoming data
View display control Device code:
1 2 3 4 5 6 7 8 9 10 11 12 |
|
View:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
|
Above That’s the entire content of this article. I hope it will be helpful to everyone’s study. For more related content, please pay attention to the PHP Chinese website!
Related recommendations:
About how to write jQuery for search paging in the YII framework
The above is the detailed content of yii2 implements paging and paging with search functions. For more information, please follow other related articles on the PHP Chinese website!