0
中空白,但仍然验证Profile Pic不能为空。我的代码如下规则。请帮我解决这个问题。虽然在yii2中上传文件,但获取错误文件不能在yii2
public function rules() {
return [
[['profile_pic'], 'file'],
[ ['profile_pic'], 'required', 'on' => 'update_pic']];
}
从控制器
$model = new PostForm(['scenario' => 'update_pic']);
if ($model->load(Yii::$app->getRequest()->getBodyParams(), '') && $model->validate()) {
return ['status' => 1, 'message' => Yii::$app->params['messages']['post_success']];
} else {
$model->validate();
return $model;
}
你可以发布剩下的代码吗? – anon
添加了调用此规则的代码 – bhavika
请阅读http://www.yiiframework.com/doc-2.0/guide-input-file-upload.html,因为您没有正确处理上传的文件。 – Bizley