system system.base system.caching system.caching.dependencies system.collections system.console system.db system.db.ar system.db.schema system.db.schema.cubrid system.db.schema.mssql system.db.schema.mysql system.db.schema.oci system.db.schema.pgsql system.db.schema.sqlite system.gii system.i18n system.i18n.gettext system.logging system.test system.utils system.validators system.web system.web.actions system.web.auth system.web.filters system.web.form system.web.helpers system.web.renderers system.web.services system.web.widgets system.web.widgets.captcha system.web.widgets.pagers zii.behaviors zii.widgets zii.widgets.grid zii.widgets.jui

CDataProviderIterator

system.web
继承 class CDataProviderIterator » CComponent
实现 Iterator, Traversable, Countable
可用自 1.1.13
源码 framework/web/CDataProviderIterator.php
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";
}

公共属性

隐藏继承的属性

属性类型描述被定义在
dataProvider CDataProvider Returns the data provider to iterate over CDataProviderIterator
totalItemCount integer Gets the total number of items to iterate over CDataProviderIterator

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__construct() Constructor. CDataProviderIterator
__get() Returns a property value, an event handler list or a behavior based on its name. CComponent
__isset() Checks if a property value is null. CComponent
__set() Sets value of a component property. CComponent
__unset() Sets a component property to be null. CComponent
asa() Returns the named behavior object. CComponent
attachBehavior() Attaches a behavior to this component. CComponent
attachBehaviors() Attaches a list of behaviors to the component. CComponent
attachEventHandler() Attaches an event handler to an event. CComponent
canGetProperty() Determines whether a property can be read. CComponent
canSetProperty() Determines whether a property can be set. CComponent
count() Gets the total number of items in the dataProvider. CDataProviderIterator
current() Gets the current item in the list. CDataProviderIterator
detachBehavior() Detaches a behavior from the component. CComponent
detachBehaviors() Detaches all behaviors from the component. CComponent
detachEventHandler() Detaches an existing event handler. CComponent
disableBehavior() Disables an attached behavior. CComponent
disableBehaviors() Disables all behaviors attached to this component. CComponent
enableBehavior() Enables an attached behavior. CComponent
enableBehaviors() Enables all behaviors attached to this component. CComponent
evaluateExpression() Evaluates a PHP expression or callback under the context of this component. CComponent
getDataProvider() Returns the data provider to iterate over CDataProviderIterator
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getTotalItemCount() Gets the total number of items to iterate over CDataProviderIterator
hasEvent() Determines whether an event is defined. CComponent
hasEventHandler() Checks whether the named event has attached handlers. CComponent
hasProperty() Determines whether a property is defined. CComponent
key() Gets the key of the current item. CDataProviderIterator
next() Moves the pointer to the next item in the list. CDataProviderIterator
raiseEvent() Raises an event. CComponent
rewind() Rewinds the iterator to the start of the list. CDataProviderIterator
valid() Checks if the current position is valid or not. CDataProviderIterator

受保护的方法

隐藏继承的方法

方法描述被定义在
loadPage() Loads a page of items CDataProviderIterator

属性详情

dataProvider 属性 只读

Returns the data provider to iterate over

totalItemCount 属性 只读
public integer getTotalItemCount()

Gets the total number of items to iterate over

方法详情

__construct() 方法
public void __construct(CDataProvider $dataProvider, integer $pageSize=NULL)
$dataProvider CDataProvider the data provider to iterate over
$pageSize integer pageSize to use for iteration. This is the number of objects loaded into memory at the same time.
源码: framework/web/CDataProviderIterator.php#48 (显示)
public function __construct(CDataProvider $dataProvider$pageSize=null)
{
    
$this->_dataProvider=$dataProvider;
    
$this->_totalItemCount=$dataProvider->getTotalItemCount();

    if((
$pagination=$this->_dataProvider->getPagination())===false)
        
$this->_dataProvider->setPagination($pagination=new CPagination());

    if(
$pageSize!==null)
        
$pagination->setPageSize($pageSize);
}

Constructor.

count() 方法
public integer count()
{return} integer the total number of items
源码: framework/web/CDataProviderIterator.php#151 (显示)
public function count()
{
    return 
$this->_totalItemCount;
}

Gets the total number of items in the dataProvider. This method is required by the Countable interface.

current() 方法
public mixed current()
{return} mixed the current item in the list
源码: framework/web/CDataProviderIterator.php#93 (显示)
public function current()
{
    return 
$this->_items[$this->_currentIndex];
}

Gets the current item in the list. This method is required by the Iterator interface.

getDataProvider() 方法
public CDataProvider getDataProvider()
{return} CDataProvider the data provider to iterate over
源码: framework/web/CDataProviderIterator.php#64 (显示)
public function getDataProvider()
{
    return 
$this->_dataProvider;
}

Returns the data provider to iterate over

getTotalItemCount() 方法
public integer getTotalItemCount()
{return} integer the total number of items to iterate over
源码: framework/web/CDataProviderIterator.php#73 (显示)
public function getTotalItemCount()
{
    return 
$this->_totalItemCount;
}

Gets the total number of items to iterate over

key() 方法
public integer key()
{return} integer the key of the current item
源码: framework/web/CDataProviderIterator.php#103 (显示)
public function key()
{
    
$pageSize=$this->_dataProvider->getPagination()->getPageSize();
    return 
$this->_currentPage*$pageSize+$this->_currentIndex;
}

Gets the key of the current item. This method is required by the Iterator interface.

loadPage() 方法
protected array loadPage()
{return} array the items from the next page of results
源码: framework/web/CDataProviderIterator.php#82 (显示)
protected function loadPage()
{
    
$this->_dataProvider->getPagination()->setCurrentPage($this->_currentPage);
    return 
$this->_items=$this->dataProvider->getData(true);
}

Loads a page of items

next() 方法
public void next()
源码: framework/web/CDataProviderIterator.php#113 (显示)
public function next()
{
    
$pageSize=$this->_dataProvider->getPagination()->getPageSize();
    
$this->_currentIndex++;
    if(
$this->_currentIndex >= $pageSize)
    {
        
$this->_currentPage++;
        
$this->_currentIndex=0;
        
$this->loadPage();
    }
}

Moves the pointer to the next item in the list. This method is required by the Iterator interface.

rewind() 方法
public void rewind()
源码: framework/web/CDataProviderIterator.php#129 (显示)
public function rewind()
{
    
$this->_currentIndex=0;
    
$this->_currentPage=0;
    
$this->loadPage();
}

Rewinds the iterator to the start of the list. This method is required by the Iterator interface.

valid() 方法
public boolean valid()
{return} boolean true if this index is valid
源码: framework/web/CDataProviderIterator.php#141 (显示)
public function valid()
{
    return 
$this->key() < $this->_totalItemCount;
}

Checks if the current position is valid or not. This method is required by the Iterator interface.