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;
        }
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 数学建模数学建模需要
  • ¥15 关于#lua#的问题,请各位专家解答!
  • ¥15 什么设备可以研究OFDM的60GHz毫米波信道模型
  • ¥15 不知道是该怎么引用多个函数片段
  • ¥30 关于用python写支付宝扫码付异步通知收不到的问题
  • ¥50 vue组件中无法正确接收并处理axios请求
  • ¥15 隐藏系统界面pdf的打印、下载按钮
  • ¥15 基于pso参数优化的LightGBM分类模型
  • ¥15 安装Paddleocr时报错无法解决
  • ¥15 python中transformers可以正常下载,但是没有办法使用pipeline