Usage at [[\yii\base\Model::behaviors()]] add the following code
~~~
return [
...
[
'class' => 'mdm\upload\UploadBehavior',
'uploadPath' => '@common/upload', // default to '@runtime/upload'
'attribute' => 'file', // attribute use to receive from FileField
'savedAttribute' => 'file_id', // attribute use to receive id of file
],
];
~~~
public function behaviors() { return [['class' => TimestampBehavior::className(), 'value' => new \yii\db\Expression('NOW()')], ['class' => UploadBehavior::className(), 'attribute' => 'file', 'savedAttribute' => 'files', 'uploadPath' => '@webroot/uploads/files']]; }
/** * @inheritdoc */ public function init() { parent::init(); $this->uploadPath = Yii::getAlias($this->uploadPath); }
public function behaviors() { return [['class' => UploadBehavior::className(), 'attribute' => 'file', 'savedAttribute' => 'avatar', 'uploadPath' => '@webroot/uploads']]; }