sasori
(Nemo Md5)
October 10, 2011, 3:12am
1
Hi, how to get the ID of the row, based from the clicked {view} button in CGridView?
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}',
),
// THE PROBLEM IS AT THIS PART,I DON'T KNOW HOW TO ASSIGN THE ID TO THE MAGNIFYING GLASS ICON
// AND CALL THE DIALOG BOX THAT WOULD SHOW THE ROWS OF DATA FROM DB.
array(
'header' => 'Copy URLs',
'class' => 'CButtonColumn',
'template' => '{view}',
'viewButtonLabel' => 'copy URL',
'viewButtonUrl' => ?
),
),
));
?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array(
'id' => 'mydialog',
'options' => array(
'title' => 'Dialog box 1',
'autoOpen' => false,
'width' => 500,
'height' => 300,
),
));
?>
//content of CJuiDialog
<?php
$this->endWidget('zii.widgets.jui.CJuiDialog');
?>
any help is appreciated . tnx in advance
sasori
(Nemo Md5)
October 10, 2011, 3:52am
2
ok, so i did it like this,
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;}',
)
),
now my problem is, how to pass the "id" to the CJuiDialog ? so that I can use that id itself
to get the correct data from my table ?
mukeshsoni
(Mukeshsoni)
October 10, 2011, 8:47am
3
sasori:
ok, so i did it like this,
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;}',
)
),
now my problem is, how to pass the "id" to the CJuiDialog ? so that I can use that id itself
to get the correct data from my table ?
If you want the dialog box to open when user clicks ‘view’ button, then you have put the code for CJuiDialog in the wrong place. The click on ‘view’ will initiate an action (in your case actionView in EmailController). This action will receive the id, which you have configured in ‘url’ parameter. The action will then render a new view, passing on the id to that view. It is in that view that you should put the CJuiDialog widget code.
Look at this thread for detailed discussion - http://goo.gl/dnxqj
sasori
(Nemo Md5)
October 10, 2011, 4:29pm
4
I don’t get it, do you have a sample snippet for it?, sorry but i can’t comprehend the discussions from the thread you posted
@sasori even i am facing the same problem