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