File tree Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Expand file tree Collapse file tree 2 files changed +15
-7
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ OUTLINE
38
38
- [ Timestamps] ( #timestamps )
39
39
- [ Database Connection] ( #database-connection )
40
40
- [ Basic Usage] ( #basic-usage )
41
- - [ Methods] ( #method )
41
+ - [ Methods] ( #methods )
42
42
- [ find()] ( #find )
43
43
- [ Query Builder Implementation] ( #query-builder-implementation )
44
44
- [ reset()] ( #reset )
@@ -56,7 +56,7 @@ OUTLINE
56
56
- [ Updates] ( #update )
57
57
- [ Deletes] ( #deletes )
58
58
- [ Accessing Data] ( #accessing-data )
59
- - [ Methods] ( #method -1 )
59
+ - [ Methods] ( #methods -1 )
60
60
- [ findone()] ( #findone )
61
61
- [ findAll()] ( #findall )
62
62
- [ save()] ( #save )
@@ -105,7 +105,7 @@ The Model would defined database coonnections and table itself.
105
105
``` php
106
106
$records = $this->Posts_model->find()
107
107
->where('is_public', '1')
108
- ->limit(0, 25)
108
+ ->limit(25)
109
109
->order_by('id')
110
110
->get()
111
111
->result_array();
@@ -340,7 +340,7 @@ Create an existent CI Query Builder instance with Model features for query purpo
340
340
``` php
341
341
$records = $this->Model->find()
342
342
->where('is_public', '1')
343
- ->limit(0, 25)
343
+ ->limit(25)
344
344
->order_by('id')
345
345
->get()
346
346
->result_array();
Original file line number Diff line number Diff line change 6
6
* Base Model
7
7
*
8
8
* @author Nick Tsai <myintaer@gmail.com>
9
- * @version 2.9.0
9
+ * @version 2.9.1
10
10
* @see https://github.com/yidas/codeigniter-model
11
11
*/
12
12
class Model extends \CI_Model implements \ArrayAccess
@@ -992,10 +992,12 @@ protected function _findByCondition($condition=NULL)
992
992
// Reset Query if condition existed
993
993
if ($ condition ) {
994
994
$ this ->_dbr ->reset_query ();
995
+ $ query = $ this ->find ();
996
+ } else {
997
+ // Support for previous find(), no need to find() again
998
+ $ query = $ this ->_dbr ;
995
999
}
996
1000
997
- $ query = $ this ->find ();
998
-
999
1001
// Check condition type
1000
1002
if (is_array ($ condition )) {
1001
1003
@@ -1018,6 +1020,12 @@ protected function _findByCondition($condition=NULL)
1018
1020
/* Single Primary Key */
1019
1021
$ query ->where ($ this ->_field ($ this ->primaryKey ), $ condition );
1020
1022
}
1023
+ else {
1024
+ // No condition situation needs to enable where protection
1025
+ $ sql = $ this ->_dbr ->get_compiled_select ('' , false ); // No reset query
1026
+ if (stripos ($ sql , 'where ' )===false )
1027
+ throw new Exception ("You could not write Model without any condition! Use ->where('1') at least. " , 400 );
1028
+ }
1021
1029
1022
1030
return $ query ;
1023
1031
}
You can’t perform that action at this time.
0 commit comments