Yii CButtonColumn onclick get this value and show a dialog box with other model data

StackOverflow https://stackoverflow.com/questions/19090776

  •  29-06-2022
  •  | 
  •  

문제

I have a IpModel and second Model is IpSenderScore ,ip_id is foreign key in Ip_history model.

Now I have create a custom button senderscore in Ip admin view like:

           'senderscore' => array(
                    'label'=>'View SenderScore of This IP',
                    'imageUrl'=>Yii::app()->request->baseUrl.'/images/loginhistory.PNG',array("style"=>"width:16px;height:16px;"),
                    'click'=>"function(){  $.fn.yiiGridView.update('user-grid', {
                                                type:'POST',
                                                url:$(this).attr('href'),
                                                success:function(data) {
                                                          $('#AjFlash').html(data).fadeIn().animate({opacity: 1.0}, 3000).fadeOut('slow');           
                                                     $.fn.yiiGridView.update('user-grid');
                                                   }
                                            })
                                            return false;
                                      }
                             ",
                     'url'=>'Yii::app()->createUrl("ipSenderScore/admin",array("ip_id"=>$data->id))',
                ),

I want to when I click on this button then show a modal window with all ip history that is saved in ipSenderScore model with this ip_id.

How it is possible?

도움이 되었습니까?

해결책

So you want a modal to show your CGridView data through clicking on the admin button?

In you Button View Paste this code:

       'senderscore'=>array(
                        'imageUrl'=>Yii::app()->request->baseUrl.'/images/loginhistory.PNG',array("style"=>"width:16px;height:16px;"),
                        //'url'=>'Yii::app()->createUrl("ipSenderScore/view/", array("id"=>$data->id,"asDialog"=>1))',                           
                         'url'=>'Yii::app()->createUrl("ipSenderScore/admin",array("ip_id"=>$data->id))',                            
                        'options'=>array(  
                        'ajax'=>array(
                                'type'=>'POST',
                                    // ajax post will use 'url' specified above 
                                'url'=>"js:$(this).attr('href')", 
                                'update'=>'#id_view',
                               ),
                         ),
             ),

After closing the widgets , paste this dive cod in your current admin view:

            <div id="id_view" style="display:none;"></div>

In your ipSenderScore controller,

               public function actionAdmin()
           {
                 // your model code
                 $this->render('admin',array('model'=>$model,));
               }

In your views/ipSenderScore/admin.php paste at the top this zii widget code:

          <?php
        //------------ add the CJuiDialog widget -----------------

      $this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog
       'id'=>'dlg-address-view',
        'options'=>array(
         'title'=>'View Address #'. $model->id,
         'autoOpen'=>true,
         'modal'=>true,
         'width'=>550,
         'height'=>470,
      ),
      ));

      //-------- default code starts here ------------------
   ?>
    <?php $this->widget('zii.widgets.grid.CGridView', array(
      // your all cgrid view original code paste here

and in the end of page close widget: endWidget('zii.widgets.jui.CJuiDialog'); ?>

Its working for me. =:)

다른 팁

you could have a controller and a custome action where you would send your ajax data there. implement your logic there and give back the data you fetched in there.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top