Ejemplo n.º 1
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCrearElemento($id)
 {
     $filtro_item = new FiltroItem();
     if (isset($_POST['FiltroItem'])) {
         $filtro_item->attributes = $_POST['FiltroItem'];
         if ($filtro_item->padre != '') {
             FiltroItem::model()->updateByPk($filtro_item->padre, array('hijos' => 1));
         } else {
             $filtro_item->padre = 0;
         }
         $filtro_item->hijos = 0;
         $filtro_item->orden = 1;
         $pgFiltro = PgFiltro::model()->with('pagina')->findByPk($filtro_item->pg_filtro_id);
         if ($filtro_item->save()) {
             Yii::app()->user->setFlash('success', $filtro_item->elemento . ' guardado con éxito');
             $this->redirect(array('pagina/view', 'id' => $pgFiltro->pagina->id));
         }
         //if($filtro_item->save())
     }
     //if(isset($_POST['FiltroItem']))
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     $pgFiltro = $id ? PgFiltro::model()->with('pagina')->findByPk($id)->id : 0;
     $filtro_item->pg_filtro_id = $pgFiltro;
     $this->render('crear-elemento', array('model' => $filtro_item));
 }