array-data-provider Array Data Provider

  1. Documentation
  2. Change Log

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
11 0
6 followers
1 464 downloads
Yii Version: 1.1
License: (not set)
Category: Others
Tags:
Developed by: Yeti
Created on: Jun 18, 2010
Last updated: 12 years ago

Downloads

show all