For creating new models in a form I use the excellent wiki article
http://www.yiiframework.com/wiki/145/cjuidialog-for-create-new-model/
But I’m not sure how to pass parameters so it updates a model?
Link to update
<?php echo CHtml::link('Update classroom',
"",
array(
'style'=>'cursor: pointer; text-decoration: underline;',
'onclick'=>"{updateClassroom(); $('#dialogClassroom').dialog('open');}"));
?>
Ajax function
function updateClassroom()
{
<?php echo CHtml::ajax(array(
'url'=>array('classroom/update'),
'data'=> "js:$(this).serialize()",
'type'=>'post',
'dataType'=>'json',
'success'=>"function(data)
...
The above displays the update form in a dialog when I use a dummy $id value in the update action controller
public function actionUpdate($id=null)
{
$id=1;
...
But if I amend the above to pass parameters via the href parameter, the update form is displayed on a separate page rather than in the dialog box
Link to update
<?php echo CHtml::link('Update classroom',
array('classroom/update',$model->classroom->id), // sending the id
array(
'style'=>'cursor: pointer; text-decoration: underline;',
'onclick'=>"{updateClassroom(); $('#dialogClassroom').dialog('open');}"));
?>
Ajax function
function updateClassroom()
{
<?php echo CHtml::ajax(array(
'url'=>'$(this).attr(\'href\')', // using the passed url
'data'=> "js:$(this).serialize()",
'type'=>'post',
'dataType'=>'json',
'success'=>"function(data)
...
Any ideas?
Thanks, Russ