/**
  * Creates a new Grupo model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Grupo();
     $models = [];
     try {
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             $models[] = $model;
             $acciones = Yii::$app->request->post('AccionGrupo');
             foreach ($acciones['id_accion'] as $accion) {
                 $modelAccion = Acciones::findOne(intval($accion));
                 if ($modelAccion) {
                     $modelAccion instanceof Acciones;
                     $modelAccionGrupo = new AccionGrupo();
                     $modelAccionGrupo->id_accion = $modelAccion->id_accion;
                     $modelAccionGrupo->id_controlador = $modelAccion->id_controlador;
                     $modelAccionGrupo->id_grupo = $model->id_grupo;
                     if ($modelAccionGrupo->save()) {
                         $models[] = $modelAccionGrupo;
                     } else {
                         throw new Exception($modelAccionGrupo->getErrors());
                     }
                 } else {
                     throw new Exception("La acción seleccionada no existe");
                 }
             }
             return $this->redirect(['view', 'id' => $model->id_grupo]);
         }
     } catch (Exception $ex) {
         foreach ($models as $modelAux) {
             $modelAux->delete();
         }
         $model->addError("nombre", $ex->getMessage());
     }
     return $this->render('create', ['model' => $model]);
 }