コード例 #1
0
 public function actionCreate()
 {
     $model = new Items();
     if ($model->load(Yii::$app->request->post())) {
         $model->file = UploadedFile::getInstance($model, 'file');
         $photoName = 'uploads/' . uniqid() . '.' . $model->file->extension;
         $model->file->saveAs($photoName);
         $model->photo = $photoName;
         $model->created = date("Y-m-d h-m-s");
         $model->author = Yii::$app->user->identity->username;
         $model->save();
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }