OctoberCMS Responsiv Uploader插件,文件具有空值

问题描述 投票:0回答:1

我使用上载器插件上载pdf文件。我遵循了在init函数中的组件上实现它的文档。这是我的以下代码

    public function init(){
    $tripFiles = $this->addComponent(
        'Responsiv\Uploader\Components\FileUploader',
        'tripFiles',
        [
            'fileTypes'             => '.jpg, .jpeg, .png, .pdf, .doc, .docx, .xls, .xlsx, .ppt, .pptx',
            'placeholderText'       => "Drag and drop file here or Browse File",
        ],
        ['deferredBinding'       => true]
    );
    $tripFiles->bindModel('files', ($this->property('tripId') ? Trip::find((int)$this->property('tripId')) : new Trip));
}


public function onSave(){
   $data = post();
    var_dump($data);
    $vacation = new Trip;
    $vacation->fill($data);
    $vacation->save(null, post('_session_key'));
}

但是我在文件中的_uploader数组上找到了具有空值的输出。

array:10 [▼
  "_handler" => "onCreateXXX"
  "_session_key" => "XXXXXXXXXX"
  "_token" => "XXXXXXXXXX"
  "name" => "XXXXX"
  "destination_name" => "XXXX"
  "purpose_id" => "1"
  "purpose" => ""
  "charge_code" => "XXXX"
  "city_id" => "1"
  "_uploader" => array:1 [▼
    "files" => ""
  ]
]

FrontEnd

{{ form_ajax('onSave')}}
   {% component 'tripFiles' %}
  <button type="submit" class="btn btn-primary w-90"> Create Trip </button>
{{ form_close() }}

所以任何人都可以帮助我解决这个问题?

php laravel filesystems octobercms uploader
1个回答
0
投票

这里的问题是有2个模型,是的,我想您无法在post中看到文件的数据。

  1. init中使用新的或基于tripId
  2. 这还是onSave中的新模型,无论如何与绑定到小部件的模型都不相关。

您需要确保在same model中使用了both case,因此,可以创建一个可以容纳模型的变量,并在两种情况下都使用它。

public $vacationModel = null;

public function init() {
    // tripFiles code
    $this->vacationModel = $this->property('tripId') 
          ? Trip::find((int)$this->property('tripId')) 
          : new Trip;
    $tripFiles->bindModel('files', $this->vacationModel);

}

public function onSave() {
    $data = post();
    $this->vacationModel->fill($data);
    $$this->vacationModel->save(null, post('_session_key'));   
}

这应该可以解决您的问题。

[如有任何疑问,请发表评论。

© www.soinside.com 2019 - 2024. All rights reserved.