【发布时间】:2013-12-27 13:44:00
【问题描述】:
我的视图文件上有 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 |
+-------------+------------+--------------+--------------+
【问题讨论】:
-
每个标签都有不同的型号。对吗?
-
是的,每个标签的模型都不同
-
您是否在模型中使用了
realations()。它使加入控制器变得更加容易,简而言之,您的控制器,您应该在主插入控制器中逐步插入和更新模型,然后如果一切正常,保存主控制器数据并重定向它。creating-and-updating-model-and-its-related-models...,@987654322 @ -
感谢您的解决方案我有多个关于lead_id 的条目我如何获取有关lead_id 的所有值,因为 findByPk() 只获取一行并且 findAll() 函数获取值但它没有显示结果它抛出错误尝试获取非对象的属性
-
请提供您当前的控制器代码,并附上更新时发布到控制器的数据转储。
标签: php join yii model multi-model-forms