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

CDataProvider

system.web
继承 abstract class CDataProvider » CComponent
实现 IDataProvider
子类 CActiveDataProvider, CArrayDataProvider, CSqlDataProvider
可用自 1.1
源码 framework/web/CDataProvider.php
CDataProvider is a base class that implements the IDataProvider interface.

Derived classes mainly need to implement three methods: fetchData, fetchKeys and calculateTotalItemCount.

公共属性

隐藏继承的属性

属性类型描述被定义在
data array Returns the data items currently available. CDataProvider
id string Returns the ID that uniquely identifies the data provider. CDataProvider
itemCount integer Returns the number of data items in the current page. CDataProvider
keys array Returns the key values associated with the data items. CDataProvider
pagination CPagination|false Returns the pagination object. CDataProvider
sort CSort|false Returns the sort object. CDataProvider
totalItemCount integer Returns the total number of data items. CDataProvider

公共方法

隐藏继承的方法

方法描述被定义在
__call() Calls the named method which is not a class method. CComponent
__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
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
getData() Returns the data items currently available. CDataProvider
getEventHandlers() Returns the list of attached event handlers for an event. CComponent
getId() Returns the ID that uniquely identifies the data provider. CDataProvider
getItemCount() Returns the number of data items in the current page. CDataProvider
getKeys() Returns the key values associated with the data items. CDataProvider
getPagination() Returns the pagination object. CDataProvider
getSort() Returns the sort object. CDataProvider
getTotalItemCount() Returns the total number of data items. CDataProvider
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
raiseEvent() Raises an event. CComponent
setData() Sets the data items for this provider. CDataProvider
setId() Sets the provider ID. CDataProvider
setKeys() Sets the data item keys for this provider. CDataProvider
setPagination() Sets the pagination for this data provider. CDataProvider
setSort() Sets the sorting for this data provider. CDataProvider
setTotalItemCount() Sets the total number of data items. CDataProvider

受保护的方法

隐藏继承的方法

方法描述被定义在
calculateTotalItemCount() Calculates the total number of data items. CDataProvider
fetchData() Fetches the data from the persistent data storage. CDataProvider
fetchKeys() Fetches the data item keys from the persistent data storage. CDataProvider

属性详情

data 属性
public array getData(boolean $refresh=false)
public void setData(array $value)

Returns the data items currently available.

id 属性
public string getId()
public void setId(string $value)

Returns the ID that uniquely identifies the data provider.

itemCount 属性 只读
public integer getItemCount(boolean $refresh=false)

Returns the number of data items in the current page. This is equivalent to count($provider->getData()). When pagination is set false, this returns the same value as totalItemCount.

keys 属性
public array getKeys(boolean $refresh=false)
public void setKeys(array $value)

Returns the key values associated with the data items.

pagination 属性
public CPagination|false getPagination(string $className='CPagination')
public void setPagination(mixed $value)

Returns the pagination object.

sort 属性
public CSort|false getSort(string $className='CSort')
public void setSort(mixed $value)

Returns the sort object.

totalItemCount 属性
public integer getTotalItemCount(boolean $refresh=false)
public void setTotalItemCount(integer $value)

Returns the total number of data items. When pagination is set false, this returns the same value as itemCount.

方法详情

calculateTotalItemCount() 方法
abstract protected integer calculateTotalItemCount()
{return} integer the total number of data items.
源码: framework/web/CDataProvider.php#44 (显示)
abstract protected function calculateTotalItemCount();

Calculates the total number of data items.

fetchData() 方法
abstract protected array fetchData()
{return} array list of data items
源码: framework/web/CDataProvider.php#34 (显示)
abstract protected function fetchData();

Fetches the data from the persistent data storage.

fetchKeys() 方法
abstract protected array fetchKeys()
{return} array list of data item keys.
源码: framework/web/CDataProvider.php#39 (显示)
abstract protected function fetchKeys();

Fetches the data item keys from the persistent data storage.

getData() 方法
public array getData(boolean $refresh=false)
$refresh boolean whether the data should be re-fetched from persistent storage.
{return} array the list of data items currently available in this data provider.
源码: framework/web/CDataProvider.php#165 (显示)
public function getData($refresh=false)
{
    if(
$this->_data===null || $refresh)
        
$this->_data=$this->fetchData();
    return 
$this->_data;
}

Returns the data items currently available.

getId() 方法
public string getId()
{return} string the unique ID that uniquely identifies the data provider among all data providers.
源码: framework/web/CDataProvider.php#50 (显示)
public function getId()
{
    return 
$this->_id;
}

Returns the ID that uniquely identifies the data provider.

getItemCount() 方法
public integer getItemCount(boolean $refresh=false)
$refresh boolean whether the number of data items should be re-calculated.
{return} integer the number of data items in the current page.
源码: framework/web/CDataProvider.php#210 (显示)
public function getItemCount($refresh=false)
{
    return 
count($this->getData($refresh));
}

Returns the number of data items in the current page. This is equivalent to count($provider->getData()). When pagination is set false, this returns the same value as totalItemCount.

getKeys() 方法
public array getKeys(boolean $refresh=false)
$refresh boolean whether the keys should be re-calculated.
{return} array the list of key values corresponding to data. Each data item in data is uniquely identified by the corresponding key value in this array.
源码: framework/web/CDataProvider.php#187 (显示)
public function getKeys($refresh=false)
{
    if(
$this->_keys===null || $refresh)
        
$this->_keys=$this->fetchKeys();
    return 
$this->_keys;
}

Returns the key values associated with the data items.

getPagination() 方法
public CPagination|false getPagination(string $className='CPagination')
$className string the pagination object class name. Parameter is available since version 1.1.13.
{return} CPagination|false the pagination object. If this is false, it means the pagination is disabled.
源码: framework/web/CDataProvider.php#69 (显示)
public function getPagination($className='CPagination')
{
    if(
$this->_pagination===null)
    {
        
$this->_pagination=new $className;
        if((
$id=$this->getId())!='')
            
$this->_pagination->pageVar=$id.'_page';
    }
    return 
$this->_pagination;
}

Returns the pagination object.

getSort() 方法
public CSort|false getSort(string $className='CSort')
$className string the sorting object class name. Parameter is available since version 1.1.13.
{return} CSort|false the sorting object. If this is false, it means the sorting is disabled.
源码: framework/web/CDataProvider.php#117 (显示)
public function getSort($className='CSort')
{
    if(
$this->_sort===null)
    {
        
$this->_sort=new $className;
        if((
$id=$this->getId())!='')
            
$this->_sort->sortVar=$id.'_sort';
    }
    return 
$this->_sort;
}

Returns the sort object.

getTotalItemCount() 方法
public integer getTotalItemCount(boolean $refresh=false)
$refresh boolean whether the total number of data items should be re-calculated.
{return} integer total number of possible data items.
源码: framework/web/CDataProvider.php#221 (显示)
public function getTotalItemCount($refresh=false)
{
    if(
$this->_totalItemCount===null || $refresh)
        
$this->_totalItemCount=$this->calculateTotalItemCount();
    return 
$this->_totalItemCount;
}

Returns the total number of data items. When pagination is set false, this returns the same value as itemCount.

setData() 方法
public void setData(array $value)
$value array put the data items into this provider.
源码: framework/web/CDataProvider.php#176 (显示)
public function setData($value)
{
    
$this->_data=$value;
}

Sets the data items for this provider.

setId() 方法
public void setId(string $value)
$value string the unique ID that uniquely identifies the data provider among all data providers.
源码: framework/web/CDataProvider.php#59 (显示)
public function setId($value)
{
    
$this->_id=$value;
}

Sets the provider ID.

setKeys() 方法
public void setKeys(array $value)
$value array put the data item keys into this provider.
源码: framework/web/CDataProvider.php#198 (显示)
public function setKeys($value)
{
    
$this->_keys=$value;
}

Sets the data item keys for this provider.

setPagination() 方法
public void setPagination(mixed $value)
$value mixed the pagination to be used by this data provider. This could be a CPagination object or an array used to configure the pagination object. If this is false, it means the pagination should be disabled.

You can configure this property same way as a component:
array(
    'class' => 'MyPagination',
    'pageSize' => 20,
),
源码: framework/web/CDataProvider.php#93 (显示)
public function setPagination($value)
{
    if(
is_array($value))
    {
        if(isset(
$value['class']))
        {
            
$pagination=$this->getPagination($value['class']);
            unset(
$value['class']);
        }
        else
            
$pagination=$this->getPagination();

        foreach(
$value as $k=>$v)
            
$pagination->$k=$v;
    }
    else
        
$this->_pagination=$value;
}

Sets the pagination for this data provider.

setSort() 方法
public void setSort(mixed $value)
$value mixed the sorting to be used by this data provider. This could be a CSort object or an array used to configure the sorting object. If this is false, it means the sorting should be disabled.

You can configure this property same way as a component:
array(
    'class' => 'MySort',
    'attributes' => array('name', 'weight'),
),
源码: framework/web/CDataProvider.php#141 (显示)
public function setSort($value)
{
    if(
is_array($value))
    {
        if(isset(
$value['class']))
        {
            
$sort=$this->getSort($value['class']);
            unset(
$value['class']);
        }
        else
            
$sort=$this->getSort();

        foreach(
$value as $k=>$v)
            
$sort->$k=$v;
    }
    else
        
$this->_sort=$value;
}

Sets the sorting for this data provider.

setTotalItemCount() 方法 (自版本 v1.1.1 可用)
public void setTotalItemCount(integer $value)
$value integer the total number of data items.
源码: framework/web/CDataProvider.php#234 (显示)
public function setTotalItemCount($value)
{
    
$this->_totalItemCount=$value;
}

Sets the total number of data items. This method is provided in case when the total number cannot be determined by calculateTotalItemCount.