九英寸小丑 / yii-exporter
用于数据导出的 Yii 框架小部件。
该软件包的规范存储库似乎已丢失,因此已冻结该软件包。
v0.9
2014-08-28 12:01 UTC
This package is not auto-updated.
Last update: 2021-06-25 22:28:16 UTC
README
此扩展提供了一个名为 CsvView 的网格小部件,允许以 CSV 格式输出大量数据集。
因为它继承自 CGridView 小部件,所以可以重用其他操作中的列配置 。
导出是流式的,所以它 速度快 且不会因大文件而耗尽内存。支持在数据提供程序中设置 CDbCriteria 的 'with' 属性进行贪婪加载 。
网格 易于扩展,这有助于创建新的导出格式。以提供的 JsonView 为例。这主要用于自定义 XML 导出。
##要求
在 Yii 1.1.13 及以上版本中进行了测试。
没有外部依赖。
##使用方法
解压到 extensions/exporter 目录。请参阅 CsvView 和 ExportAction 类以获取所有选项的参考。
###单个操作
通过使用提供的 ExportAction 类,可以在控制器中定义一个用于下载导出数据的操作。
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 ), ); }
###在服务器端创建文件
创建一个小部件并捕获其内容
$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, )); ob_start(); ob_implicit_flush(false); $widget->run(); $file_contents = ob_get_clean();
###扩展
请参阅提供的 JsonView 类,了解如何创建新的导出格式的示例。在许多情况下,只需要重写三个方法
- renderHeader
- renderBody
- renderFooter
##资源