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 Rubrica();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Rubrica'])) {
         $model->attributes = $_POST['Rubrica'];
         if ($model->save()) {
             //Salva os campos adicionais
             if (isset($_POST['Campo'])) {
                 foreach ($_POST['Campo'] as $cmp) {
                     $campo = new RubricaCampo();
                     $campo->attributes = $cmp;
                     $campo->cod_rubrica = $model->cod_rubrica;
                     if (!$campo->save()) {
                         throw new CHttpException(500, 'Não foi possível salvar o campo' . $campo->chave);
                     }
                 }
             }
             //Redireciona
             $this->redirect(array('view', 'id' => $model->cod_rubrica));
         }
     }
     $this->render('create', array('model' => $model));
 }