我正在尝试上传文件而我设置了规则,问题是即使我选择文件也有错误请上传文件。有什么不对,因为我注意到有一些验证规则,我已完成this
[['file'], 'file', 'skipOnEmpty' => FALSE,'on'=>'new']
,
在控制器处设置
$type = new \app\models\Buildobjects();
$type->scenario="new";
[编辑]我的控制器是
if ($type->load(Yii::$app->request->post()) && $type->validate()) {
$type->file = UploadedFile::getInstance($type, 'file');
$up = $this->generateRandomString(3);
if (isset($type->file)) {
if ($type->upload($up, $type->file)) {
$type->file = $up . $type->file->baseName . '.' . $type->file->extension;
// file is uploaded successfully
//return;
}
}
$type->save();
$this->redirect(Url::to(['site/archive', 'param' => $param]), 302);
}