Package | system.web |
---|---|
Inheritance | class CDataProviderIterator » CComponent |
Implements | Iterator, Countable, Traversable |
Since | 1.1.13 |
Source Code | framework/web/CDataProviderIterator.php |
$dataProvider = new CActiveDataProvider("User"); $iterator = new CDataProviderIterator($dataProvider); foreach($iterator as $user) { echo $user->name."\n"; }
Property | Type | Description | Defined By |
---|---|---|---|
dataProvider | CDataProvider | Returns the data provider to iterate over | CDataProviderIterator |
totalItemCount | integer | Gets the total number of items to iterate over | CDataProviderIterator |
Method | Description | Defined By |
---|---|---|
__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 |
Method | Description | Defined By |
---|---|---|
loadPage() | Loads a page of items | CDataProviderIterator |
Returns the data provider to iterate over
Gets the total number of items to iterate over
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. |
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.
public integer count()
| ||
{return} | integer | the total number of items |
public function count()
{
return $this->_totalItemCount;
}
Gets the total number of items in the dataProvider. This method is required by the Countable interface.
public mixed current()
| ||
{return} | mixed | the current item in the list |
public function current()
{
return $this->_items[$this->_currentIndex];
}
Gets the current item in the list. This method is required by the Iterator interface.
public CDataProvider getDataProvider()
| ||
{return} | CDataProvider | the data provider to iterate over |
public function getDataProvider()
{
return $this->_dataProvider;
}
Returns the data provider to iterate over
public integer getTotalItemCount()
| ||
{return} | integer | the total number of items to iterate over |
public function getTotalItemCount()
{
return $this->_totalItemCount;
}
Gets the total number of items to iterate over
public integer key()
| ||
{return} | integer | the key of the current item |
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.
protected array loadPage()
| ||
{return} | array | the items from the next page of results |
protected function loadPage()
{
$this->_dataProvider->getPagination()->setCurrentPage($this->_currentPage);
return $this->_items=$this->dataProvider->getData(true);
}
Loads a page of items
public void next()
|
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.
public void rewind()
|
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.
public boolean valid()
| ||
{return} | boolean | true if this index is valid |
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.
Signup or Login in order to comment.