maxmilian
(Andreas Strahle)
March 23, 2010, 7:54am
1
This might be obvious to some people but im a bit lost here
Whats the guidelines here when are you supposed to use a CActiveDataProvider.
is it only when using like a cgridview etc ?
Im not sure I totally understand the dataprovider is there any extended documentation about this "feature"
Also it would make more sense to just a add a list of object to the view whats the benefit of the dataprovider ?
jsoo
(Jeff)
March 23, 2010, 12:08pm
3
CGridView, CListView, and related widgets require it. The combination of CActiveDataProvider and the widget makes sorting and pagination easy. Maybe there’s more to it than that; I don’t know.
eliasb
(Elias)
March 25, 2010, 9:23pm
4
Here is a data provider that takes an array of CActiveRecords in the config:
class CArrayDataProvider extends CDataProvider {
public $dataArray;
public $modelClass;
public function __construct($confModelClass, $config)
{
$config = new CConfiguration($config);
$config->applyTo($this);
$this->modelClass=$confModelClass;
}
protected function fetchData() {
$startIndex=0;
$length=$this->getTotalItemCount();
if(($pagination=$this->getPagination())!==false)
{
$pagination->setItemCount($this->getTotalItemCount());
$length=$pagination->pageSize;
$startIndex=$pagination->currentPage*$pagination->pageSize;
}
return array_slice($this->dataArray, $startIndex, $length, true);
}
protected function fetchKeys() {
return array_keys($this->getData());
}
protected function calculateTotalItemCount() {
return count($this->dataArray);
}
}
Usage for example:
$dataProvider=new CArrayDataProvider('Producer', array(
'dataArray'=>$model->producers,
'pagination'=>array(
'pageSize'=>10,
)
));
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'application.views.producer._listItemView',
));
romanoza
(Romanoza)
March 31, 2010, 6:09am
6
SOLVED http://www.yiiframework.com/forum/index.php?/topic/7678-zii-for-non-active-records/
Hi there.
I have a problem:
There is 2 arrays, first for the column names (example):
$names['closed'] = 'Done';
$names['active'] = 'In progress';
and array of values:
$values['Type1']['closed'] = 35;
$values['Type1']['active'] = 23;
$values['Type2']['closed'] = 55;
$values['Type2']['active'] = 575;
$values['Type3']['closed'] = 44;
$values['Type4']['active'] = 325;
I need to show it in CGridView like this:
|In Progress|Done
Type1| 23 | 35
Type2| 575 | 55
Type3| 0 | 44
Type4| 325 | 0
Is it possible?