File tree Expand file tree Collapse file tree
user_guide_src/source/libraries Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -46,15 +46,27 @@ To customize a query for pagination in a model, you can add
4646:doc: `Query Builder <../database/query_builder >` methods before ``paginate() ``
4747method.
4848
49- To add WHERE conditions:
49+ Adding WHERE
50+ ------------
51+
52+ If you want to add WHERE conditions, you can specify conditions directly:
5053
5154.. literalinclude :: pagination/003.php
5255 :lines: 2-
5356
57+ You can move the conditions to a separate method:
58+
59+ .. literalinclude :: pagination/017.php
60+
61+ .. literalinclude :: pagination/018.php
62+ :lines: 2-
63+
64+ Adding JOIN
65+ -----------
66+
5467You can join another table:
5568
5669.. literalinclude :: pagination/016.php
57- :lines: 2-
5870
5971.. important :: It is important to understand that the ``Model::paginate()`` method
6072 uses the **Model ** and the **Query Builder ** instance in the Model.
Original file line number Diff line number Diff line change 11<?php
22
3- // You can specify conditions directly .
3+ // In your Controller .
44$ model = new \App \Models \UserModel ();
55
66$ data = [
77 'users ' => $ model ->where ('ban ' , 1 )->paginate (10 ),
88 'pager ' => $ model ->pager ,
99];
10-
11- // You can move the conditions to a separate method.
12- class UserModel extends Model
13- {
14- // ...
15-
16- public function banned ()
17- {
18- $ this ->builder ()->where ('ban ' , 1 );
19-
20- return $ this ; // This will allow the call chain to be used.
21- }
22- }
23-
24- $ data = [
25- 'users ' => $ model ->banned ()->paginate (10 ),
26- 'pager ' => $ model ->pager ,
27- ];
Original file line number Diff line number Diff line change 11<?php
22
3+ namespace App \Models ;
4+
5+ use CodeIgniter \Model ;
6+
37class NewsModel extends Model
48{
59 protected $ table = 'news ' ;
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Models ;
4+
5+ use CodeIgniter \Model ;
6+
7+ class UserModel extends Model
8+ {
9+ // ...
10+
11+ public function banned ()
12+ {
13+ $ this ->builder ()->where ('ban ' , 1 );
14+
15+ return $ this ; // This will allow the call chain to be used.
16+ }
17+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ // In your Controller.
4+ $ model = new \App \Models \UserModel ();
5+
6+ $ data = [
7+ 'users ' => $ model ->banned ()->paginate (10 ),
8+ 'pager ' => $ model ->pager ,
9+ ];
You can’t perform that action at this time.
0 commit comments