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.
Resources ¶
Documentation ¶
Requirements ¶
- Yii 1.1 or above
Installation ¶
- Extract the release file under
protected/extensions
Usage ¶
In 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.
Change Log ¶
18 June 2010 ¶
- Initial release.
19 June 2010 ¶
- V1.1 - Fixed array_multisort() argument issue
22 June 2010 ¶
- V1.2 - Fixed handling of empty arrays
And what about arraydataprovider?
What's the difference between this one and arraydataprovider?? Why is it categorized as Miscellaneous instead of Database???
Now 5/5
mod'd line
$sortArgs[] = $directions[$index];
to
$sortArgs[] = &$directions[$index];
and it's working perfectly for me now.
Thanks Yeti
very handy extension
I marked a bug in the Forum I was getting, but this would've had a 5/5 if not for the one issue.
Great extension!!
Thanks a lot, it's just a great extension!!!!
Nice, but how to access current record in i.e. CGridView?
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:
foreach ($arrayDataProvider->data AS $elem) { echo($elem['keyValue']); }
But this doesn't seem to work within a CButtonColumn.
Does anyone hava a hint on that?
Check CArrayDataProvider first
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.
Used that before
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.
pagination property
how i set the pagination property for clistview in this arraydataprovider extension.
Re: pagination property
Please use CArrayDataProvider; this handles pagination and sorting.
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.