这是我的代码
<?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');
?>
我的问题是,如何将点击的行的ID传递给对话框? ,以便我可以使用该ID以在对话框内呈现正确的内容? 因为在该ID的帮助下,我可以像这样进行数据库查询
SELECT u.url,e.secretKey FROM tbl_emails AS e, tbl_urls AS u
WHERE emailid = ID;
答案 0 :(得分:2)
使用jQuery数据方法。 例如:
<?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');
?>