This is what my code looks like right now. As you can see I’m using tabs and CJuiDialog. The way the corde is right now, the Dialog actually comes up.
<?php
/* @var $this PeopleController */
/* @var $dataProvider CActiveDataProvider */
$this->breadcrumbs=array(
'Peoples',
);
?>
<h1>People</h1>
<?php $this->beginWidget('system.web.widgets.CClipWidget', array('id'=>'Opciones')); ?>
<?php echo CHtml::link('Create People', '#', array(
'onclick'=>'$("#mydialog").dialog("open"); return false;',
));
?>
<?php
$this->beginWidget('zii.widgets.jui.CJuiDialog',array(
'id'=>'mydialog',
// additional javascript options for the dialog plugin
'options'=>array(
'title'=>'Create People',
'autoOpen'=>false,
'modal'=>true,
),
));
?>
s
<?php $model = new People;
echo $this->renderPartial('_form', array('model'=>$model)); ?>
<?php $this->endWidget('zii.widgets.jui.CJuiDialog'); ?>
<script type="text/javascript">
function addPeople()
{
<?php echo CHtml::ajax(array(
'url'=>array('people/create'),
'data'=> "js:$(this).serialize()",
'type'=>'post',
'dataType'=>'json',
'success'=>"function(data)
{
if (data.status == 'failure')
{
$('#dialogPeople div.divForForm').html(data.div);
// Here is the trick: on submit-> once again this function!
$('#dialogPeople div.divForForm form').submit(addPeople);
}
else
{
$('#dialogPeople div.divForForm').html(data.div);
setTimeout(\"$('#dialogPeople').dialog('close') \",3000);
}
} ",
))?>;
return false;
}
</script>
<?php $this->endWidget(); ?>
<?php $this->beginWidget('system.web.widgets.CClipWidget', array('id'=>'Vista')); ?>
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view',
)); ?>
<?php $this->endWidget(); ?>
<?php
$tabParameters = array();
foreach($this->clips as $key=>$clip)
$tabParameters['tab'.(count($tabParameters)+1)] = array('title'=>$key, 'content'=>$clip);
?>
<?php $this->widget('system.web.widgets.CTabView', array('tabs'=>$tabParameters)); ?>
The first problem is if i remove the following line:
$model = new People;
which i took from actionCreate in the controller, then the page won’t load because of this line:
echo $this->renderPartial('_form', array('model'=>$model))
saying that model is an undefined variable…
But what’s more, by leaving the code the way it is, it just won’t save records to the database… And the worst part is I can’t even check if it’s trying to do the job because when I set the rules to validate, it also crashes and quotes some lines from yii’s CValidator.php