我是 Yii 框架的初学者。我想在我的 createform 中有一个从我的另一个表链接的弹出窗口。这样做的目的是我有一个保管箱,如果没有我想选择的数据。我会先创作。我想在我的表 1 create.php 中有一个弹出框,它将在我的表 2 中获得创建表单。这就是我开始的。这里似乎有什么问题?
这是我的 table1 create.php 代码
<?php echo CHtml::link('New Day',"",
array(
'style'=>'cursor:pointer; text-decoration:underline;',
'onClick'=>"{doDay(); $('#dialogDay).dialog('open');}"));?>
<?php
$this->beginWidget('zii.Widgets.jui.CJuiDialog',array(
'id'=>'dialogDay',
'options'=>array(
'title'=>'Add New Day',
'autoOpen'=>false,
'modal'=>true,
'width'=>550,
'height'=>470,
),
));
?>
<div class="divForForm"></div>
<?php $this->endWidget();?>
<script type="text/javascript">
function doDay()
{
<?php echo CHtml::ajax(array(
'url'=>array('day/NewDay'),
'data'=>"js:$(this).serialize()",
'type'=>'post',
'dataType'=>'json',
'success'=>"function(data)
{
if(data.status == 'failure')
{
$('#dialogDay div.divForForm').html(data.div);
$('#dialogDay div.divForForm form').submit(doDay);
}
else
{
window.location.href = ".Yii::app()->getBaseUrl().";
}
}",
))?>
return false;
}
</script>
在我的表 2 控制器中
public function actionNewDay()
{
$model= new Day;
if(isset($_POST['ajax']) && $_POST['ajax']=='day-form')
{
$model->attributes=$_POST['Day'];
echo CActiveForm::validate($model);
Yii::app()->end();
}
if(isset($_POST['Day']))
{
$model->attributes=$_POST['Day'];
$name=$model->name;
$mon=$model->mon;
$tue=$model->tue;
$wed=$model->wed;
$thurs=$model->thurs;
$fri=$model->fri;
$sat=$model->sat;
$sun=$model->sun;
$dayassign = new DayAssign();
if($model->save())
{
$dayassign->varName = $name;
$dayassign->varMon = $mon;
$dayassign->varTue = $tue;
$dayassign->varWed = $wed;
$dayassign->varThurs = $thurs;
$dayassign->varFri = $fri;
$dayassign->varSat = $sat;
$dayassign->varSun = $sun;
if($dayassign->save())
{
if(Yii::app()->request->isAjaxRequest)
{
echo CJSON::encode(array(
'status'=>'success',
));
}
else{
$url = Yii::app()->getBaseUrl();
Yii::app()->getRequest()->redirect($url);
}
}
}
if(Yii::app()->request->isAjaxRequest)
{
echo CJSON::encode(array(
'status'=>'failure',
'div'=>$this->renderPartial('day',array('model'=>$model),true)));
exit;
}
else
$this->render('day',array('model'=>$model,));
}
}