【问题标题】:php YII Cgridview & Checkbox + Different Modelphp YII Cgridview & Checkbox + 不同模型
【发布时间】:2013-09-14 12:24:02
【问题描述】:

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

在视图 (_form) 中,我显示了 2 个不同的表格:billing & cost 它们通过列 IDCLIENTIDBILLING

连接

当我创建一个新的账单时,我想选择(带有复选框)其中插入的成本,并且 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,
                ));
        }

提前感谢您的任何回复

【问题讨论】:

    标签: php yii cgridview


    【解决方案1】:

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

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

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

    干杯

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-22
      相关资源
      最近更新 更多