@@ -11,7 +11,7 @@ <h1>Development - Models</h1>
1111 < li > < a href ="#creating_record "> Creating Record</ a > </ li >
1212 < li > < a href ="#updating_record "> Updating Record</ a > </ li >
1313 < li > < a href ="#deleting_record "> Deleting Record</ a > </ li >
14- < li > < a href ="#reading_record "> Reading Record </ a > </ li >
14+ < li > < a href ="#reading_records "> Reading Records </ a > </ li >
1515 < li > < a href ="#additional_methods "> Additional Methods</ a > </ li >
1616 </ ul >
1717 </ li >
@@ -415,8 +415,8 @@ <h4>Deleting Record</h4>
415415< br >
416416
417417
418- < a name ="reading_record "> </ a >
419- < h4 > Reading Record </ h4 >
418+ < a name ="reading_records "> </ a >
419+ < h4 > Reading Records </ h4 >
420420To read data from a database table, we can use one of the find methods as follows.
421421
422422< pre name ="dlhl " class ="php ">
@@ -433,6 +433,20 @@ <h4>Reading Record</h4>
433433// Finds all rows satisfying the specified conditions with %LIKE%
434434$news = News:model()-> findAll(CConfig::get('db.prefix').$this-> _tableTranslation.'.news_text LIKE :keywords', array(':keywords'=> '%'.$keywords.'%'));
435435</ pre >
436+
437+ Reading records with chunks. The chunk method breaks the record set into small parts of a given size
438+ < pre name ="dlhl " class ="php ">
439+ $posts = [];
440+ // 1st parameter - conditions
441+ // 2nd parameter - condition parameters
442+ // 3rd parameter - chunk size
443+ // 4th parameter - callback function
444+ Posts::model()-> chunk($conditions, [], 10, function ($records) use(&$posts){
445+ foreach ($records as $key => $record) {
446+ $posts[] = $record;
447+ }
448+ });
449+ </ pre >
436450< br >
437451
438452
0 commit comments