doukong1901 2014-10-12 22:05
浏览 30
已采纳

如何在Silverstripe CMS中将大量子对象下载为CSV?

I'm working on a Silverstripe project which has a Batch > Item relationship.

A Batch can have up to 50,000 Items.

This is how the relationship is set-out:

class Item extends DataObject {

  private static $has_one = array(
      'Batch' => 'Batch'
  );

class Batch extends DataObject {

  private static $has_many = array(
      'Items' => 'Item'
  );

class BatchAdmin extends ModelAdmin {

  private static $managed_models = array(
      'Batch',
      'Item'
  );

This natively gives the CMS user the ability to download all Items as a CSV from the CMS.

I'm trying to work out two things:

  1. How do I make sure that large downloads don't fail due to lack of memory/ script time etc?

  2. How do I add an "Export to CSV" button to each Batch which downloads only the Items in that batch as a CSV?

  • 写回答

1条回答 默认 最新

  • duanbinren8906 2014-10-15 23:52
    关注

    To add an Export to CSV button to Batch which exports the related Items we add a GridFieldExportButton to the Batch CMSFields:

    class Batch extends DataObject {
    
        private static $has_many = array(
            'Items' => 'Item'
        );
    
        public function getCMSFields() {
            $itemsConfig = GridFieldConfig_RelationEditor::create();
            $itemsConfig->addComponent(new GridFieldExportButton());
    
            $itemsField = new GridField(
                'Items',
                'Items',
                $this->Items(),
                $itemsConfig
            ); 
    
            $fields = new FieldList(
                $itemsField
            );
    
            return $fields;
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 这个复选框什么作用?
  • ¥15 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下