This extension is deprecated; please use CArrayDataProvider.
This extension is a data provider (CDataProvider) for array data with paging and sorting support for use in (for example) CGridView.
There is a demo in the package.
protected/extensionsIn your controller:
Yii::import('application.extensions.arrayDataProvider.*'): class YourController extends CController { public function actionYourAction() { $dataProvider = new ArrayDataProvider($arrayData); $this->render('view', array('dataProvider'=>$dataProvider); } }
$arrayData can be an array of associative arrays:
array( array('atomic_number'=>1, 'symbol'=>'H', 'name'=>'Hydrogen'), array('atomic_number'=>2, 'symbol'=>'He', 'name'=>'Helium'), array('atomic_number'=>3, 'symbol'=>'Li', 'name'=>'Lithium'), );
The data is accessed in the view using the keys of the associative arrays as attribute names.
Note: Attribute names (keys) must be valid PHP variable names.
$arrayData can also be an associative array or a simple array:
array( 'H' => 'Hydrogen', 'He' => 'Helium', 'Li' => 'Lithium', ); // or array( 'Hydrogen', 'Helium', 'Lithium', );
where the data is accessed using the attribute names 'key' and 'value', where for the simple array 'key' will be numeric (the array is transformed internally to an array of associative arrays).
In your view:
// For array of arrays $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider' => $dataProvider, 'columns' => array('atomic_number', 'symbol', 'name'), )); // else $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider' => $dataProvider, 'columns' => array('key', 'value'), ));
See AdpController.php and demo.php for an example.
Total 9 comments
Please use CArrayDataProvider; this handles pagination and sorting.
how i set the pagination property for clistview in this arraydataprovider extension.
Thanks for the answer. I used to go with CArrayDataProvider before and switched a couple of days ago because of the nice implementation of sorting. With CArrayDataProvider I was able to access the current element via $data->datasetID but unfortunately this doesn't work anymore.
Please check CArrayDataProvider(http://www.yiiframework.com/doc/api/1.1/CArrayDataProvider "CArrayDataProvider") first. It was implemented in yii since 1.1.4 and should cover your needs instead of the extension.
The only issue I'm afraid I have with this very nice extension is that it seems I'm unable to access the current Dataset for further options on the displayed records like ...view&datasetID=4711
Outside CGridView I can access the entire DataProviderArray very handy:
But this doesn't seem to work within a CButtonColumn.
Does anyone hava a hint on that?
Thanks a lot, it's just a great extension!!!!
What's the difference between this one and arraydataprovider?? Why is it categorized as Miscellaneous instead of Database???
mod'd line
$sortArgs[] = $directions[$index];
to
$sortArgs[] = &$directions[$index];
and it's working perfectly for me now.
Thanks Yeti
I marked a bug in the Forum I was getting, but this would've had a 5/5 if not for the one issue.
Leave a comment
Please login to leave your comment.