Yii 1.1: activerecorditerator

A Helper Class to allow for iteration over a large set of active records using a CActiveDataProvider
8 followers

This extension solves a very specific problem that I had. I need to generate dynamic results using thousands of very large ActiveRecords. Doing so was causing a memory overflow on shared hosts, so I wrote this helper class that uses pagination of a CActiveDataProvider but provides a simple Iterator interface to iterate over the records in batches.

It's not fancy, it's just useful.

Requirements

Yii 1.1 or above

Usage

  1. Place the class in a directory that will be imported.
  2. Create a CActiveDataProvider
  3. Instantiate over the provider using the ActiveRecordIterator as below:
$activeDataProvider= new CActiveDataProvider('Post', ...);
$iterator = new ActiveRecordIterator($activeDataProvider, 10);
foreach ($iterator as $index => $record) {
  // Do Something amazing here
}

Resources

Be the first person to leave a comment

Please to leave your comment.

Create extension