Exemplo n.º 1
0
 /** 
  * Creates a new Exercise model. 
  * If creation is successful, the browser will be redirected to the 'view' page. 
  * @return mixed 
  */
 public function actionCreate()
 {
     $model = new Exercise();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         if (Yii::$app->request->post()['Exercise']['test']) {
             //echo json_encode(Yii::$app->request->post()['Exercise']);
             foreach (Yii::$app->request->post()['Exercise']['exerciseTests'] as $exts) {
                 $modelET = new \common\models\ExerciseTest();
                 $modelET->value = $exts['value'];
                 $modelET->istrue = $exts['istrue'];
                 $modelET->exercise_id = $model->getPrimaryKey();
                 $modelET->save();
             }
         }
         return $this->redirect(['control']);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }