/**
  * Creates a new StuGuardians model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new StuGuardians();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->stu_guardian_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Example #2
0
 public function actionAddguardian($sid)
 {
     $model = $this->findModel($sid);
     $guard = new StuGuardians();
     if ($guard->load(Yii::$app->request->post()) && !empty($_POST['StuGuardians']['guardian_name'])) {
         $guard->attributes = $_POST['StuGuardians'];
         if (empty($_POST['StuGuardians']['guardian_email'])) {
             $guard->guardian_email = NULL;
         } else {
             $guard->guardian_email = strtolower($_POST['StuGuardians']['guardian_email']);
         }
         $guard->guardia_stu_master_id = $model->stu_master_id;
         $emg_cont = $guard->find()->where(['is_emg_contact' => 1, 'guardia_stu_master_id' => $model->stu_master_id, 'is_status' => 0])->exists();
         if ($emg_cont) {
             $guard->is_emg_contact = 0;
         } else {
             $guard->is_emg_contact = 1;
         }
         $guard->created_by = Yii::$app->getid->getId();
         $guard->created_at = new \yii\db\Expression('NOW()');
         if ($guard->save()) {
             return $this->redirect(['stu-master/view', 'id' => $model->stu_master_id, '#' => "guardians"]);
         } else {
             return $this->render('add_guardian', ['model' => $model, 'guard' => $guard]);
         }
     }
     return $this->render('add_guardian', ['model' => $model, 'guard' => $guard]);
 }