Requirements ¶
Yii 2.0 or above
Usage ¶
See source for installation.
Attach behavior to model
public function behaviors()
{
return [
...
[
'class' => 'mdm\upload\UploadBehavior',
'attribute' => 'file', // required, use to receive input file
'savedAttribute' => 'file_id', // optional, use to link model with saved file.
'uploadPath' => '@common/upload', // saved directory. default to '@runtime/upload'
],
];
}
Modify your controller
public function actionCreate()
{
...
if($model->load(Yii::$app->request->post()) && $model->validate()){
if($model->saveUploadedFile() !== false){
$model->save();
// do something
}
return $this->redirect();
}
return $this->render('create',['model' => $model])
}
If you have any questions, please ask in the forum instead.
Signup or Login in order to comment.