示例#1
0
 /**
  * Creates a new Keluarga model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Keluarga();
     if ($model->load(Yii::$app->request->post())) {
         $no_kk = substr($model->kepala_keluarga, 0, 6) . Yii::$app->formatter->asDate('now', 'ddMMyy') . $model->id;
         $model->id = $no_kk;
         $model->tanggal_terbit = date('Y-m-d');
         $model->tanggal_pembaruan = date('Y-m-d');
         $model->status = 1;
         $updatable = BaseUpdatable::findOne($model->kepala_keluarga);
         $updatable->no_kk = $no_kk;
         $updatable->status_keluarga = 1;
         //echo var_dump($model);
         if ($model->save() && $updatable->save()) {
             $this->writeLog("Membuat kartu keluarga dengan nomor KK {$keluarga->id}");
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             VarDumper::dump($model->getErrors(), 5678, true);
             //return $this->actionIndex();
         }
     } else {
         return $this->renderAjax('create', ['model' => $model]);
     }
 }