【发布时间】:2016-09-11 21:57:29
【问题描述】:
如何解决错误?
这是我的 htm 代码(按钮上传)
{{ form_open({files: true, request: 'onFileUpload'}) }}
<!--File Input-->
<input type="file" name="file-upload" required="required">
<!--File Input-->
<!--Submit/Upload Button-->
<button type="submit">Upload</button>
{{ form_close() }}
这是组件的php代码
public function onFileUpload()
{
$file = new System\Models\File;
$file->data = Input::file('file-upload');
$file->save();
// Attach the uploaded file to your model
$model->file()->add($file);
// The above line assumes you have proper attachOne or attachMany relationships defined on your model
$model->file_path = url('/') . $model->file->getPath();
$model->save();
return Redirect::back();
}
这是正确的 attachMany 关系吗?
public $attachMany = [
'files' => 'System\Models\File',
];
}
我不太确定代码,因为我是 10 月 cms 的新手 任何人都可以举一些例子吗? 如何创建拖放文件上传器组件?
【问题讨论】:
-
正如错误所说:您正试图向 $model->file() 添加一些内容,但从未启动变量 $model。所以 $model 在那一点上什么都不是。
-
我添加了这个 $model = new Uploadedfile;(
标签: php file-upload model components octobercms