session problem help

The part I am working on is one of the modules of a web application powered by Yii 1.4.x .I have a CGridView in my index view file. Then inside it,I have custom buttons. One of the buttons is popping up a dialog box. here’s the snippet for that custom button that i mentioned

                'see' => array(

                     'label' => 'View',

                     'url' => 'Yii::app()->controller->createUrl("myControllerName/view",array("id" => "$data->id"))',

                     'options' => array(

                         'ajax' => array(

                            'type' => 'POST',

                             'url' => "js:$(this).attr('href')",

                             'dataType' => "json",

                             'async' => false,

                             'success' => 'function(data){

                                    $("#detail-dialog").dialog("open"); return false;


                             'update' => '#detail'




Here is the snippet of the controller action that named ‘view’ in the controller

    public function actionView(){

        $gid = $_GET['id'];

        $data = array();

        if(Yii::app()->request->isAjaxRequest) {

            $model = MyModelName::model()->findById($gid);

            if (!empty($model) || !is_null($model)) {

                $attributes = $model->getAttributes();

                $result = MyModelName::model()->findByKey($attributes['key'], $attributes['new_key']);


                    foreach($result as $key => $val){

                        $data['model'][$key] = $val;


                    $data['code'] = self::CODE_AJAX_SUCCESS;


            } else {

                $data['code'] = self::CODE_AJAX_ERROR;


           $_SESSION['ajaxresponse'] = json_encode($data);

           echo json_encode($data);



at the bottom of the CGridView of my view file, I have this snippet of the CJuiDialog

$this->beginWidget('zii.widgets.jui.CJuiDialog', array(

    'id' => 'detail-dialog',

    'options' => array(

        'title' => 'Edit Data',

        'autoOpen' => false,

        'modal' => false,

        'width' => 600,

        'height' => 500,

        'close' => 'js:function(){

            //nothing here



)); ?>

$result = $_SESSION['ajaxresponse'];

$this->renderPartial('_view',array('viewajaxresponse' => $result));


Whenever I click a row in the CGridView, It pops out the CJuiDialog box, along with the ajax response inside it

because I rendered partial it from the session.

Now the issue is, let’s say I closed the CJuiDialog box then I clicked the 2nd row or another row in the CGridView, the contents of the Dialog box remains with the first row that I clicked unless I force refresh the browser like two or three times before the data inside the Dialog box changes .How to solve this problem?

I even implemented an ajax function of the ‘close’ event of the CJuiDialog box in order to kill the session


                    url: "'.Yii::app()->controller->createUrl("MyControllerName/destroysession", array("s"=>"ajaxresponse")).'",

                    type: "POST",

                    dataType: "json",

                    async: true,

                    success: function(data){




and then in the controller action

    public function actionDestroysession(){

        $name = !empty($_GET['s'])?$_GET['s']:'';



            $data['code'] = self::CODE_AJAX_SUCCESS;

            echo json_encode($data);



        echo $data['code'] = self::CODE_AJAX_ERROR;



the problem this time, is , it totally kills the session even if you see in the function, I only killed a specific session variable because I passed the name, but then when I click any of the rows in CGridView, no data displays in side the CJuiDialog box … so how to solve this session problem ? I need help badly :unsure: