コード例 #1
0
 public function actionCreate()
 {
     $model = new UserProfil();
     if ($model->load(Yii::$app->request->post())) {
         $model->user_id = Yii::$app->user->id;
         $model->tgl_lahir = date('Y-m-d', strtotime($_POST['UserProfil']['tgl_lahir']));
         $model->created_at = date('Y-m-d h:i:s');
         $foto = UploadedFile::getInstance($model, 'foto');
         if ($foto) {
             $ext = end(explode(".", $foto->name));
             $extt = $foto->extension;
             $model->foto = Yii::$app->security->generateRandomString() . "." . $extt;
         }
         if ($model->save()) {
             $foto->saveAs('../uploads/foto_profil/' . $model->foto);
             Yii::$app->session->setFlash('success', 'Profil berhasil Di simpan');
             return $this->redirect(['index']);
         } else {
             Yii::$app->session->setFlash('warning', 'Simpan Gagal');
         }
     } else {
         return $this->render('_formN', ['model' => $model]);
     }
 }