exporter A grid widget for exporting data, reusing columns definition and with support for eager loading using 'with' in CDbCriteria.

  1. Requirements
  2. Usage
  3. Resources

This extension provides a grid widget called CsvView that allows output a large dataset in a CSV format.

Because it inherits from the CGridView widget, column configuration from other actions can be reused.

Exports are streamed, so it's fast and doesn't run out of memory with large files. Eager loading by setting the 'with' property of CDbCriteria in the dataProvider is supported.

The grid is easily extendable which helps creating new export formats. See the provided JsonView as an example. This is intended for custom XML exports.


Tested in Yii 1.1.13 and above.

No external dependencies.


Extract to extensions/exporter directory. See the CsvView and ExportAction classes for all options reference.

Single action

By using the provided ExportAction class an action for downloading files with exported data could be created by defining in the controller:

public function actions() {
    return array(
        'export' => array(
            'class'     => 'ext.exporter.ExportAction',
            'columns'   => $this->getIndexColumns(), // reuse existing configuration
            'modelClass' => 'SomeModel', // provide your CActiveRecord model with the search() method or define 'dataProvider' in the 'widget' property
            'widget'    => array('filename' => 'export.csv'), // all properties of CsvView widget
Creating file on the server side

Create a widget and capture it's contents:

$widget = Yii::app()->widgetFactory->createWidget($controller, 'ext.exporter.CsvView', array(
    'columns' => $columns, // reuse existing configuration
    'dataProvider' => $model->search(), // or create it any other way
	'disableBuffering' => false,
	'disableHttpHeaders' => true,
$file_contents = ob_get_clean();

See the provided JsonView class for an example how to create new export formats. In many cases just three methods need to be overwritten:

  • renderHeader
  • renderBody
  • renderFooter


1 1
1 161 downloads
Yii Version: Unknown
License: BSD-2-Clause
Category: Database
Developed by: nineinchnick
Created on: Aug 14, 2013
Last updated: 8 years ago


show all

Related Extensions