Session Variables: Select columns

Hi Guys.

The reason for this, is I need some help with the following case:

I’m implementing a grid.CGridView for a table whose information must be brought based on the columns selected by the user, via checkboxes.

That is, if my table has 8 columns, then 8 checkbox are displayed, and the user selects 5 columns, and then he clicks the submit for the CGridView refreshes and shows the selected columns.

The detail is that the selected columns are storing in session variables through a private function that i’m calling on my admin controller (where is my table):

We must clarify that there is an array of checkboxes with the names of the columns in the table ($ _POST [‘columnas’]).

private function fijarColumnasAdmin()

{

/* COMPROBAMOS QUE LA SESIÓN DE CAMPOS EXISTA PARA QUE LA TABLA SE REFRESQUE */

if(!isset(Yii::app()->session[‘adminMoviles’])){

Yii::app()->session['adminMoviles'] = array("nombre");

}

else

{

if(isset($_POST['columnas'])){


  Yii::app()->session['adminMoviles'] = $_POST['columnas'];


}


elseif(empty($_POST['columnas'])){


  //Yii::app()->session['adminMoviles'] = array();


}

}

}

And I have a double trouble:

  • In the line that I have put the ‘//’, if I commented it, it preserves the columns that I have selected, even when I advance on the pager of my table and/or I navigate in my web application, but it hasthe disadvantage that if I do not select any columns, then not shows my empty table, but I get the last columns I selected.

  • And if it is uncommented: when I refresh the table after selecting some columns, then when I advance on the pager and / or I move in different parts of the application and return to the myTable/admin, The selected columns are lost.

My question is:

What could I do to ensure I do not miss my selected columns (selecting or not selecting columns), when I use the pager of my table and/or I move in different parts of my application until I return again to myTable/admin ?

Thanks for your attention.