2017-05-26 17 views
3

我有一個具有使用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工作臺上實際上傳了它。 enter image description here

然而,當我點擊保存在後臺,我得到「試圖獲得非對象的財產」

這裏是什麼在afterSave()函數。

public function afterSave() 

{ 

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

} 

是否有可能在後端甚至上傳並在保存之前/之後移動文件?

回答

6

問題是該文件尚未完全存在於afterSave()中,它仍然作爲延遲綁定存在。試試這個:

$this->return_file()->withDeferred($this->sessionKey)->first()->getPath(); 
相關問題