PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, February 15, 2022

[FIXED] how to fix this session with my CJuiDialog box content in Yii 1.4.x?

 February 15, 2022     jquery, yii, yii-components     No comments   

Issue

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']);
                if(!empty($result)){
                    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);
           exit;
        }

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));
$this->endWidget('zii.widgets.jui.CJuiDialog');

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

  $.ajax({
            url: "'.Yii::app()->controller->createUrl("MyControllerName/destroysession", array("s"=>"ajaxresponse")).'",
            type: "POST",
            dataType: "json",
            async: true,
            success: function(data){
               document.location.reload(true);
        }
    });

and then in the controller action

public function actionDestroysession(){
        $name = !empty($_GET['s'])?$_GET['s']:'';
        if(isset($name)){
            unset($_SESSION[$name]);
            $data['code'] = self::CODE_AJAX_SUCCESS;
            echo json_encode($data);
            exit;
        }
        echo $data['code'] = self::CODE_AJAX_ERROR;
        exit;

    }

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 ?


Solution

The fix for this was, never use sessions when creating CJuiTabs inside a CjuiDialog box. better generate the Cjuitab from the controller, then use it as an ajax response to the view file that fires the CjuiDialog box



Answered By - sasori
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing