Hi, this might be an easy problem but I have been staring at it for some time.
I’m trying to render view in a dialog when a button is clicked. I’ve been looking at this guide and tried to modify the code for my purpose but with no luck. I think the problem is the script but I’m not very good at javascript.
ProjectsController
/**
* Displays a particular model.
* @param integer $id the ID of the model to be displayed
*/
public function actionView($id)
{
if (Yii::app()->request->isAjaxRequest)
{
echo CJSON::encode(array(
'div'=>$this->renderPartial('view',array('model'=>$this->loadModel($id))))),
exit;
}
else
{
$this->render('view',array(
'model'=>$this->loadModel($id),
));
}
}
And the index
'enddate',
'note',
array(
'class'=>'CButtonColumn',
'template'=>'{open}',
'buttons'=>array(
'open'=>array(
'label'=>'Open',
'click'=>'function(){viewProject(); $("#dialogProject").dialog("open");}',
),
),
),
),
)); ?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog', array( // the dialog
'id'=>'dialogProject',
'options'=>array(
'title'=>'Project',
'autoOpen'=>false,
'modal'=>true,
'width'=>700,
'height'=>500,
),
)); ?>
<div class="divForView"></div>
<?php $this->endWidget();?>
<script type="text/javascript">
function viewProject()
{
<?php echo CHtml::ajax(array(
//'url'=>'Yii::app()->createUrl("projects/view", array("id"=>$data->Id))',
'url'=>array('projects/view'),
'data'=> "js:$(this).serialize()",
'dataType'=>'json',
'success'=>"function(data)
{
$('#dialogProject div.divForView').html(data.div);
} ",
))?>;
return false;
}
</script>
Any help would be appreciated.
Zed