0

我的视图文件上有 3 个选项卡

第一个标签: 学生

第二个标签:教育

第三个标签:就业

我的表结构:

学生表:

+-------------+------------+--------------+------------+-------------+
|    id(PK)   |  lead_id   |  st_name     |   st_email |  st_phone   |
+-------------+------------+--------------+------------+-------------+

线索详情:

+-------------+-------------+
|    id(PK)   | lead_ref_id |  
+-------------+-------------+

教育

+-------------+------------+--------------+--------------+
|    id(PK)   |  lead_id   |education_type|education_year|
+-------------+------------+--------------+--------------+

就业:

+-------------+------------+---------------+---------------------+
|    id(PK)   |  lead_id   |Employment_type|Employment_experience|
+-------------+------------+---------------+---------------------+

当我去更新动作时,我必须根据lead_id显示数据

我的学生查看文件代码:

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'lead-student-detail-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.

// See class documentation of CActiveForm for details on this.
'enableAjaxValidation'=>false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
    )); ?>

<p class="note">Fields with <span class="required">*</span> are required.</p>



<div class="row">
    <?php echo $form->labelEx($model,'st_name'); ?>
    <?php echo   $form->textField($model,'st_name',array('size'=>50,'maxlength'=>50)); ?>
    <?php echo $form->error($model,'st_name'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'st_email'); ?>
    <?php echo $form->textField($model,'st_email',array('size'=>50,'maxlength'=>50)); ?>
    <?php echo $form->error($model,'st_email'); ?>
</div>

<div class="row">
    <?php echo $form->labelEx($model,'st_phone'); ?>
    <?php echo $form->textField($model,'st_phone'); ?>
    <?php echo $form->error($model,'st_phone'); ?>
</div>



    </div><!-- form -->

我的教育视图代码

 <div class="form">

 <?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'lead-target-education-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(array($target)); ?>


</div>

    <?php echo $form->labelEx($target,'education_type'); ?>
    <?php echo $form->textField($target,'education_type'); ?>
    <?php echo $form->error($target,'education_type'); ?>

  </div>    


</div>

    <?php echo $form->labelEx($target,'academic_year'); ?>
    <?php echo $form->textField($target,'academic_year[]'); ?>
    <?php echo $form->error($target,'academic_year'); ?>

  </div>

我应该如何编写动作更新代码,以便数据根据 而lead_id不是主键显示id并根据lead_id.

从评论更新

铅和教育表之间存在一对多的关系。

+-------------+------------+--------------+--------------+
|    id(PK)   |  lead_id   |education_type|education_year|
+-------------+------------+--------------+--------------+ 
|     1       |    1       |    10        |    2003      |
+-------------+------------+--------------+--------------+
|     2       |    1       |    12        |    2005      |
+-------------+------------+--------------+--------------+
4

1 回答 1

0

在我看来,您只需要进行查找即可。所以你最终会得到的是

$lead_id = 1;

$student = Student::model()->find(array('condition'=>'lead_id = :lead_id','params'=>array(':lead_id'=>$lead_id)));
$student->name = 'newvalue';
$student->save();

$education = Education::model()->find(array('condition'=>'lead_id = :lead_id','params'=>array(':lead_id'=>$lead_id)));
$education->education_year = 'newvalue';
$education->save();

$employment = Employment::model()->find(array('condition'=>'lead_id = :lead_id','params'=>array(':lead_id'=>$lead_id)));
$employment->employment_type = 'newvalue';
$employment->save();

在这里,我们使用 find 访问了三个模型。我们lead_id通过参数输入:lead_id,这是绑定到lead_id变量':lead_id'=>$lead_id

然后我可以如图所示更改字段,使用该$model->save();功能保存新信息。

如果这不是您想要的信息,请发表评论,我会根据您的建议进行更新。

于 2013-12-28T23:18:38.890 回答