我在YII中很新,对不起,如果这是一个愚蠢的问题。
视图中的(_form)我显示了两个不同的表:结算&的成本 它们通过colums连接 IDCLIENT &的 IDBILLING
当我创建新的结算时,我想选择(带有复选框)成本插入其中, cost.IDBILLING 必须使用 IDBILLING 进行更新创建
我强调了未知部分。
这里_form代码:
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'billing-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'IDCLIENT'); ?>
<h2><?php echo $client->IDCLIENT; ?></h2>
<?php echo $form->error($model,'IDCLIENT'); ?> <br>
<h3><?php
echo $client->name." ".$client->surname."<br>".$client->document;
?></h3>
</div>
<div class="row">
<?php echo $form->labelEx($model,'datefrom'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
'name'=>"Billing[datefrom]", // the name of the field
'value'=>$model->datefrom, // pre-fill the value
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd', // optional Date formatting
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
<?php echo $form->error($model,'datefrom'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'dateto'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
'name'=>"Billing[dateto]", // the name of the field
'value'=>$model->dateto, // pre-fill the value
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd', // optional Date formatting
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
<?php echo $form->error($model,'dateto'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'date'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
'name'=>"Billing[date]", // the name of the field
'value'=>$model->date, // pre-fill the value
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd', // optional Date formatting
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
<?php echo $form->error($model,'date'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'state'); ?>
<?php echo $form->textField($model,'state',array('size'=>16,'maxlength'=>16)); ?>
<?php echo $form->error($model,'state'); ?>
</div>
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'cost-grid',
'dataProvider'=>new CActiveDataProvider('Cost',array(
'criteria' => $criteria,
'pagination' => array('pageSize' => 10),
)),
'selectableRows' => 2,
//'filter'=>$model,
'columns'=>array(
array('class'=>'CCheckBoxColumn','value'=>'$data->IDCOST/*??????IS THIS CORRET????*/',),
'IDCOST',
'advance',
'spent',
'date',
'type',
'scope',
/*
'note',
'IDCLIENT',
*/
),
)); ?>
控制器:
public function actionCreate($IDCLIENT)
{
$model=new Billing;
$client = new Client;
$criteria=new CDbCriteria;
// Uncomment the following line if AJAX validation is needed
// $this->performAjaxValidation($model);
//$this->IDCLIENT= $IDCLIENT;
$client = Client::model()->findByPk((int)$IDCLIENT);
$criteria->condition = "IDCLIENT = ".$client->IDCLIENT." AND (IDBILLING IS NULL OR IDBILLING = 0)";
$criteria->order = "date DESC";
if(isset($_POST['Billing']))
{
$model->attributes=$_POST['Billing'];
$model->IDCLIENT=$client->IDCLIENT;
if($model->save()){
$cost= new Cost;
if($cost=Cost::model()->updateAll(array( 'IDBILLING' => $model->IDBILLING ), 'IDCOST = '.#########WHAT I HAVE TO INSERT HERE???########))
$this->redirect(array('view','id'=>$model->IDBILLING));
}
}
$this->render('create',array(
'model'=>$model,
'client'=>$client,
'criteria'=>$criteria,
));
}
预先感谢您的回复
答案 0 :(得分:0)
你可以像这样刷新你的网格(在javascript中):
$.fn.yiiGridView.update("your-grid-name");
将ajax所需的数据提交给另一个控制器并保存或随意保存,然后刷新网格并显示新结果!
欢呼声