【问题标题】:"Trying to get property of non-object" when uploading a file that isn't saved上传未保存的文件时“尝试获取非对象的属性”
【发布时间】:2017-10-27 12:56:50
【问题描述】:

我有一个模型,其文件关系使用 OctoberCMS 的 system_files。

public $attachOne = [
    'return_file' => ['System\Models\File', 'public' => false, 'delete' => true]
    ];

在 fields.yaml 我有表单

   return_file:
        label: Attach File
        type: fileupload
        mode: file
        span: right

现在在我保存之前或之后,我想将图像从其目录移动到我插件中的自定义目录。 afterSave() 似乎没有检索文件路径来移动它。

但是在system_files中我看到MySQL workbench中其实已经上传了。

然而,当我在后端点击保存时,我得到“尝试获取非对象的属性”

这是 afterSave() 函数中的内容。

public function afterSave()

{

$custom_path = plugins_path() . '/acme/request/uploads/';
$file = $this->return_file->getPath();
$move_file = $file->move($custom_path);

}

是否可以在后端上传并在保存之前/之后移动文件?

【问题讨论】:

    标签: php laravel octobercms


    【解决方案1】:

    问题是文件在afterSave() 中还没有完全存在,它仍然作为延迟绑定存在。试试这个:

    $this->return_file()->withDeferred($this->sessionKey)->first()->getPath();
    

    【讨论】:

      猜你喜欢
      • 2016-05-02
      • 1970-01-01
      • 1970-01-01
      • 2020-02-18
      • 1970-01-01
      • 2021-02-26
      • 1970-01-01
      • 2013-12-22
      • 2015-09-30
      相关资源
      最近更新 更多