简体   繁体   中英

can we use sessions in cgridview to store the value obatined on cbuttoncolumn clicked

i need to know can we use sessions in cgridview to store the value obatined.

something like

in view

//  cgridview
    ..........
 ' name',
  array
 ('header'=>'ID',
 'value'=>'Yii::app()->SESSION['id']=$data["rid"]'),

 .......

this is my gridview

 <?php
 $this->widget('zii.widgets.grid.CGridView', array(
 'dataProvider'=>$dataP10,
 'ajaxUpdate'=>true,
 'columns'=>array(

  array('name'=>' Name','value'=>'$data["name"]'),

 array('name'=>' createdate','value'=>'$data["createdate"]'),

  array(
 'class'=>'CButtonColumn',
 'template'=>'{view}',
 'buttons'=>array(

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

 ),

  ));
  ?>

here data["id"] i dont want it to be querystring but something in session for that particular record its id to be in session

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

can anyone let me know can this happen if so then do suggest your guidance

Your grid definition is mystery to me !

What I think you need is sth like this, ajax event on cbuttoncolumn

 array(
            'class'=>'CButtonColumn',
            'header'=>'Add',
            'template'=>'{add}',
            'buttons'=>array(
                'add'=>array(
                    'label'=>'Mark It',                        
                    'url'=>'Yii::app()->createUrl("Controller/markIt", array("id"=>$data['id']))',
                    'options'=>array(
                        'ajax'=>array(
                            'type'=>'POST',
                            'url'=>'js:$(this).attr("href")',
                            'success'=>'function(data, textStatus, jqXHR){
                                var json = $.parseJSON(data);
                             }',
                            'error'=>'function(jqXHR, textStatus, errorThrown){
                                alert(errorThrown)
                            }',
                        ),
                    ),
                ),
               'view'=>array(
                    'url'=>'Yii::app()->createUrl("controller/view",array("id"=>$data["id"]))',
                ),
            ),
        ),

In the controller you have to define a function e. g

Controller

  public function markIt($id){
     if(Yii::app()->getRequest()->getIsAjaxRequest()) {
         $_SESSION['id']=$id;
     }
  }

public function view($id){
    //view records 
}

Now given your comments down I am puzzled , you want to click on the record and --> Add the respective record id to session --> View the record

If you need to perform both actions you just need to put this at the top of view funciton eg function view($id){ //check if record found $_SESSION['id']=$id; ... reset of the code } function view($id){ //check if record found $_SESSION['id']=$id; ... reset of the code }

else see above code where you have two buttons one to set the value to session other to view the record . You need to be clear about the flow of actions first .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM