Yii 1.1: array-data-provider

Array Data Provider
6 followers

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

Total 9 comments

#7700 report it
Yeti at 2012/04/10 01:22pm
Re: pagination property

Please use CArrayDataProvider; this handles pagination and sorting.

#7687 report it
Riyas at 2012/04/09 03:22pm
pagination property

how i set the pagination property for clistview in this arraydataprovider extension.

#6746 report it
dadudeness at 2012/02/02 10:23am
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.

#6744 report it
yugene at 2012/02/02 09:21am
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.

#6739 report it
dadudeness at 2012/02/02 02:41am
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?

#4511 report it
yugene at 2011/07/15 03:39am
Great extension!!

Thanks a lot, it's just a great extension!!!!

#267 report it
rmrcoxa at 2010/07/23 03:15pm
And what about arraydataprovider?

What's the difference between this one and arraydataprovider?? Why is it categorized as Miscellaneous instead of Database???

#385 report it
PRWilly at 2010/06/18 10:56pm
Now 5/5

mod'd line
$sortArgs[] = $directions[$index];
to
$sortArgs[] = &$directions[$index];
and it's working perfectly for me now.

Thanks Yeti

#386 report it
PRWilly at 2010/06/18 07:52pm
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.

Leave a comment

Please to leave your comment.

Create extension
  • Yii Version: 1.1
  • License: Other Open Source License
  • Developed by: Yeti
  • Category: Others
  • Votes: +11 / -1
  • Downloaded: 1,341 times
  • Created on: Jun 18, 2010
  • Last updated: Feb 3, 2012