예제 #1
0
 /**
  * Creates a new Securitas model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Securitas();
     $ajax = Yii::$app->request->isAjax;
     if ($model->load(Yii::$app->request->post())) {
         try {
             if ($model->save()) {
                 Yii::$app->session->setFlash('success', 'Data berhasil disimpan.');
                 $model = new Securitas();
             } else {
                 Yii::$app->session->setFlash('error', 'Data gagal disimpan.');
             }
             if ($ajax) {
                 return $this->renderAjax('create', ['model' => $model]);
             } else {
                 return $this->render('create', ['model' => $model]);
             }
         } catch (Exception $e) {
             Yii::$app->session->setFlash('error', 'Kode sudah ada, pilih kode lain.');
             return $this->renderAjax('create', ['model' => $model]);
         }
     } else {
         if ($ajax) {
             return $this->renderAjax('create', ['model' => $model]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     }
 }