Class CDataProviderIterator
CDataProviderIterator allows iteration over large data sets without holding
the entire set in memory.
CDataProviderIterator iterates over the results of a data provider, starting
at the first page of results and ending at the last page. It is usually only
suited for use with CActiveDataProvider
.
For example, the following code will iterate over all registered users
(active record class User) without running out of memory, even if there are
millions of users in the database.
$dataProvider = new CActiveDataProvider("User");
$iterator = new CDataProviderIterator($dataProvider);
foreach($iterator as $user) {
echo $user->name."\n";
}
-
CComponent
-
CDataProviderIterator
implements
Iterator,
Countable
Methods summary
public
|
#
__construct( CDataProvider $dataProvider, integer $pageSize = null )
Constructor.
Parameters
- $dataProvider
CDataProvider
$dataProvider the data provider to iterate over
- $pageSize
integer $pageSize pageSize to use for iteration. This is the number of objects loaded
into memory at the same time.
|
public
CDataProvider
|
#
getDataProvider( )
Returns the data provider to iterate over
Returns the data provider to iterate over
Returns
|
public
integer
|
#
getTotalItemCount( )
Gets the total number of items to iterate over
Gets the total number of items to iterate over
Returns
integer the total number of items to iterate over
|
protected
array
|
#
loadPage( )
Loads a page of items
Returns
array the items from the next page of results
|
public
mixed
|
#
current( )
Gets the current item in the list. This method is required by the Iterator
interface.
Gets the current item in the list. This method is required by the Iterator
interface.
Returns
mixed the current item in the list
Implementation of
|
public
integer
|
#
key( )
Gets the key of the current item. This method is required by the Iterator
interface.
Gets the key of the current item. This method is required by the Iterator
interface.
Returns
integer the key of the current item
Implementation of
|
public
|
#
next( )
Moves the pointer to the next item in the list. This method is required by
the Iterator interface.
Moves the pointer to the next item in the list. This method is required by
the Iterator interface.
Implementation of
|
public
|
#
rewind( )
Rewinds the iterator to the start of the list. This method is required by the
Iterator interface.
Rewinds the iterator to the start of the list. This method is required by the
Iterator interface.
Implementation of
|
public
boolean
|
#
valid( )
Checks if the current position is valid or not. This method is required by
the Iterator interface.
Checks if the current position is valid or not. This method is required by
the Iterator interface.
Returns
boolean true if this index is valid
Implementation of
|
public
integer
|
#
count( )
Gets the total number of items in the dataProvider. This method is required
by the Countable interface.
Gets the total number of items in the dataProvider. This method is required
by the Countable interface.
Returns
integer the total number of items
Implementation of
|
Methods inherited from CComponent
__call(),
__get(),
__isset(),
__set(),
__unset(),
asa(),
attachBehavior(),
attachBehaviors(),
attachEventHandler(),
canGetProperty(),
canSetProperty(),
detachBehavior(),
detachBehaviors(),
detachEventHandler(),
disableBehavior(),
disableBehaviors(),
enableBehavior(),
enableBehaviors(),
evaluateExpression(),
getEventHandlers(),
hasEvent(),
hasEventHandler(),
hasProperty(),
raiseEvent()
|
Magic properties summary
public
CDataProvider
|
$dataProvider
|
#
the data provider to iterate over
the data provider to iterate over
|
public
integer
|
$totalItemCount
|
#
the total number of items in the iterator
the total number of items in the iterator
|