Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * use \mdm\upload\FileModel
- *
- * ganti News::$thumnail_url dengan News::$image_id, tipenya integer.
- *
- */
- public function actionCreate()
- {
- $model = new News();
- $model->scenario = 'create';
- if($model->load(Yii::$app->request->post())){
- $file = UploadedFile::getInstance($model,'image');
- $model->image = $file;
- //...
- if($model->validate() && ($fmodel=FileModel::saveAs($file, Yii::$app->params['uploadPath']))!==false){
- $model->image_id = $fmodel->id;
- $model->save();
- Yii::$app->session->setFlash('success', 'Upload Success');
- return $this->redirect(['view','id'=>$model->id]);
- }else{
- // ...
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement