Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.74 KB | None | 0 0
  1. /**
  2.  * use \mdm\upload\FileModel
  3.  *
  4.  * ganti News::$thumnail_url dengan News::$image_id, tipenya integer.
  5.  *
  6.  */
  7. public function actionCreate()
  8. {
  9.     $model = new News();
  10.     $model->scenario = 'create';
  11.     if($model->load(Yii::$app->request->post())){
  12.         $file = UploadedFile::getInstance($model,'image');
  13.         $model->image = $file;
  14.         //...
  15.         if($model->validate() && ($fmodel=FileModel::saveAs($file, Yii::$app->params['uploadPath']))!==false){
  16.             $model->image_id = $fmodel->id;
  17.             $model->save();
  18.             Yii::$app->session->setFlash('success', 'Upload Success');
  19.             return $this->redirect(['view','id'=>$model->id]);
  20.         }else{
  21.             // ...
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement