php - how to pass the view id to the CJuiDialog box?

821

here's my code

<?php
$this->widget('zii.widgets.grid.CGridView',array(
   'dataProvider'=>$dataProvider,
    'columns' => array(
        array(
          'name' => 'emailaddress',
          'htmlOptions' => array(
            'width' => '30',  
          ),
        ),
        array(
          'name' => 'secretkey',
          'htmlOptions' => array(
            'width' => '40px',  
          ),
        ),
        array(
          'header' => 'Options',
          'class' => 'CButtonColumn',  
          'template' => '{view}{update}{delete}',
        ),
        array(
          'header' => 'Copy URLs',
          'class' => 'CButtonColumn',
          'template' => '{copy}',
          'buttons' => array(
            'copy' => array(
                'label' => 'copy url',
                'url' => 'Yii::app()->createUrl("emails/view",array("id"=>$data["emailid"]))',
                'options' => array('id' => $data["emailid"]),
                'click' => 'function(){$("#mydialog").dialog("open"); return false;}',
            )  
          ),
      ),
    ),
));

?>

<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
   'id' => 'mydialog',
   'options' => array(
     'title' => 'URL + Key',
     'autoOpen' => false,
     'width' => 500,
     'height' => 300,
   ),
));


//THIS PART SHOULD RECEIVE THE ID SO THAT I CAN QUERY TO THE DB TABLE

?>

<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>

my question is, how will i pass the ID of the clicked row, to the Dialog box? , so that I can use that ID in order to render the correct contents inside the dialog box ? because with the help of that ID, i can do a db query like this

SELECT u.url,e.secretKey FROM tbl_emails AS e, tbl_urls AS u
WHERE emailid = ID;
573

Answer

Solution:

Use the jQuery data method. For example:

<?php
...
'copy' => array(
    'label' => 'copy url',
    'url' => 'Yii::app()->createUrl("emails/view",array("id"=>$data["emailid"]))',
    'options' => array('id' => $data["emailid"]),
    'click' => 'function(){$("#mydialog").data("emailid",$(this).attr("id")).dialog("open"); return false;}',
)
...
?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
   'id' => 'mydialog',
   'options' => array(
     'title' => 'URL + Key',
     'autoOpen' => false,
     'width' => 500,
     'height' => 300,
     'close'=>"js:function(){
            $('#mydialog').removeData('emailid');
        }",
   ),
));

// GETTING THE ID
?>
$('#mydialog').data('emailid');

<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>

People are also looking for solutions to the problem: mysql - php+mysqlupdate

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.