예제 #1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     /*$model=new Siswa;
     
     		// Uncomment the following line if AJAX validation is needed
     		// $this->performAjaxValidation($model);
     
     		if(isset($_POST['Siswa']))
     		{
     			$model->attributes=$_POST['Siswa'];
     			if($model->save())
     				$this->redirect(array('view','id'=>$model->nis));
     		}
     
     		$this->render('create',array(
     			'model'=>$model,
     		));*/
     $model = new Siswa();
     $model2 = new Keluarga();
     $model3 = new Ayah();
     $model4 = new Ibu();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Siswa'])) {
         $model3->attributes = $_POST['Ayah'];
         $model4->attributes = $_POST['Ibu'];
         $model2->attributes = $_POST['Keluarga'];
         $model2->nik_ayah = $_POST['Ayah']['nik_ayah'];
         $model2->nik_ibu = $_POST['Ibu']['nik_ibu'];
         $model->attributes = $_POST['Siswa'];
         $model->no_kk = $_POST['Keluarga']['no_kk'];
         $valid = $model->validate();
         $valid = $model2->validate() && $valid;
         $valid = $model3->validate() && $valid;
         $valid = $model4->validate() && $valid;
         $savefoto;
         if (strlen(trim(CUploadedFile::getInstance($model, 'foto'))) > 0) {
             $savefoto = CUploadedFile::getInstance($model, 'foto');
             $model->foto = 'isims-' . $model->nis . '.' . $savefoto->extensionName;
         }
         if ($valid) {
             if ($model3->save() && $model4->save()) {
                 if ($model2->save()) {
                     if ($model->save()) {
                         if (strlen(trim($model->foto)) > 0) {
                             $savefoto->saveAs(Yii::app()->basePath . '/../images/siswa/' . $model->foto);
                         }
                         $this->redirect(array('view', 'id' => $model->nis));
                     }
                 }
             }
         }
     }
     $this->render('create', array('model' => $model, 'model2' => $model2, 'model3' => $model3, 'model4' => $model4));
 }