/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Courses();
     $model_1 = new Batches();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Courses'])) {
         $model_1->attributes = $_POST['Batches'];
         $model->attributes = $_POST['Courses'];
         $model->validate();
         if ($model_1->validate()) {
             if ($model->save()) {
                 $list = $_POST['Batches'];
                 if (!$list['start_date']) {
                     $s_d = "";
                 } else {
                     $s_d = date('Y-m-d', strtotime($list['start_date']));
                 }
                 if (!$list['end_date']) {
                     $e_d = "";
                 } else {
                     $e_d = date('Y-m-d', strtotime($list['end_date']));
                 }
                 $model_1->course_id = Yii::app()->db->getLastInsertId();
                 $model_1->start_date = $s_d;
                 $model_1->end_date = $e_d;
                 $model_1->save();
                 $this->redirect(array('/courses'));
             }
         }
     }
     $this->render('create', array('model' => $model, 'model_1' => $model_1));
 }