私は YII を始めたばかりで、ばかげた質問でしたら申し訳ありません。
ビュー (_form) で 2 つの異なるテーブルを表示しています:請求とコストは列IDCLIENTと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,
));
}
返信ありがとうございます