0

我是 YII 的新手,如果这是一个愚蠢的问题,我很抱歉。

在视图(_form)中,我正在显示 2 个不同的表:计费成本 ,它们通过列 IDCLIENTIDBILLING连接

当我创建一个新帐单时,我想选择(带有复选框)其中插入的成本,并且必须使用刚刚创建的IDBILLING更新cost.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,
                ));
        }

提前感谢您的任何回复

4

1 回答 1

0

你可以像这样刷新你的网格(在javascript中):

$.fn.yiiGridView.update("your-grid-name");

通过 ajax 将您想要的数据提交到另一个控制器并保存它或您想要的任何内容,然后刷新您的网格并显示您的新结果!

干杯

于 2013-09-15T13:28:20.290 回答