Exemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Pools();
     $answers = new Answers();
     if (isset($_POST['Pools'])) {
         $model->attributes = $_POST['Pools'];
         if ($model->save()) {
             if (isset($_POST['Answers_name'])) {
                 foreach ($_POST['Answers_name'] as $answer) {
                     $variant = new Answers();
                     $variant->name = $answer;
                     $variant->pool_id = $model->id;
                     $variant->save();
                 }
                 Yii::app()->user->setFlash('success', Yii::t('main', 'Данные успешно сохранены!'));
                 $this->redirect(array('update', 'id' => $model->id));
             }
         } else {
             Yii::app()->user->setFlash('error', Yii::t('main', 'Ошибка!'));
         }
     }
     $this->render('create', array('answers' => $answers, 'model' => $model));
 }