...
Code Block | ||||
---|---|---|---|---|
| ||||
use App\Lib\Util\PaginatedSqlIterator; class myClass { public function doSomething() { $iterator = new PaginatedSqlIterator( // Model to query $this->People->getTarget(), // Conditions ['co_id' => $coId] ); // Initial record count $total = $iterator->count(); $i = 0; foreach($iterator as $k => $v) { // Do something for this particular record ... // Every 1000 records, refresh the count just in case new records have been added. // Note this is for informational purposes for the calling code *only*, and is not // required. The iterator will correctly retrieve subsequently added records // regardless of whether or not count() is called. if($i % 1000 == 0) { $total = $iterator->count(true); } } } } |
getMembers()
In Registry v5, various Tables implement getMembers()
calls, that correctly create the PaginatedSqlIterator for that table and return it. This includes GroupsTable, PeopleTable, and PersonRolesTable.