2016-02-09 11:39:26 3323次浏览 0条回答 0 悬赏 10 金钱

本来做一个页面用于提交 用户的教育背景的,至少填写一项背景,就设置了两个场景 'edu_1'还有默认场景,实现方式如下:
但是控制器取回的 提交信息中,只包含最后一个教育背景,前两个,不知为啥被覆盖了。 以下代码该如何修改
model:

<?php
	namespace app\models;
	use yii\db\ActiveRecord;
	class Education_experience extends ActiveRecord{
		
		public function scenarios(){
			$scenarios = parent::scenarios();
			$scenarios['edu_1'] = ['uer_id','date_begin','date_end','university','department','degree','teacher'];
			return $scenarios;
		}
		
		public function rules(){
			return [
				[['date_begin','date_end','university','department','degree','teacher'],'required','on'=>'edu_1'],	
			];
		}
	}
?>

controller:

public function actionUpdateEducationExperience(){
 		$edu_1 = new Education_experience(['scenario'=>'edu_1']);
 		$edu_2 = new Education_experience;
 		$edu_3 = new Education_experience;
 		if(\Yii::$app->request->isPost){
 			print_r(\Yii::$app->request->post());
 			exit;
 		}
 		return $this->render('update_education_experience',['edu_1'=>$edu_1,'edu_2'=>$edu_2,'edu_3'=>$edu_3]);
 	}

view:

<div class='edu'>
<h1>Education Experience</h1>
<?php
	use dosamigos\datepicker\DatePicker;
	use yii\widgets\ActiveForm;
	use yii\helpers\Html;
	$form = ActiveForm::begin([
			'id'=>'edu-exp',
			'enableAjaxValidation'=>false,
	]);
?>
->1
<?=$form->field($edu_1,'date_begin')->widget(DatePicker::className(),[
//		'inline'=>true,
		'template'=>'{addon}{input}',
		'language'=>'zh-CN',
		'clientOptions'=>[
			'autoclose'=>true,
			'format'=>'yyyy-mm-dd',
],
		
])->label('start time')?>
<?=$form->field($edu_1,'date_end')->widget(DatePicker::className(),[
	//	'inline'=>true,
		'template'=>'{addon}{input}',
		'language'=>'zh-CN',
		'clientOptions'=>[
			'autoclose'=>true,
			'format'=>'yyyy-mm-dd',
],
		
])->label('end time')?>

<?=$form->field($edu_1,'university') ?>
<?=$form->field($edu_1,'department')?>
<?=$form->field($edu_1,'degree')?>
<?=$form->field($edu_1,'teacher')?>


->2
<?=$form->field($edu_2,'date_begin')->widget(DatePicker::className(),[
//		'inline'=>true,
		'template'=>'{addon}{input}',
		'language'=>'zh-CN',
		'clientOptions'=>[
			'autoclose'=>true,
			'format'=>'yyyy-mm-dd',
],
		
])->label('start time')?>
<?=$form->field($edu_2,'date_end')->widget(DatePicker::className(),[
	//	'inline'=>true,
		'template'=>'{addon}{input}',
		'language'=>'zh-CN',
		'clientOptions'=>[
			'autoclose'=>true,
			'format'=>'yyyy-mm-dd',
],
		
])->label('end time')?>

<?=$form->field($edu_2,'university') ?>
<?=$form->field($edu_2,'department')?>
<?=$form->field($edu_2,'degree')?>
<?=$form->field($edu_2,'teacher')?>


->3
<?=$form->field($edu_3,'date_begin')->widget(DatePicker::className(),[
//		'inline'=>true,
		'template'=>'{addon}{input}',
		'language'=>'zh-CN',
		'clientOptions'=>[
			'autoclose'=>true,
			'format'=>'yyyy-mm-dd',
],
		
])->label('start time')?>
<?=$form->field($edu_3,'date_end')->widget(DatePicker::className(),[
	//	'inline'=>true,
		'template'=>'{addon}{input}',
		'language'=>'zh-CN',
		'clientOptions'=>[
			'autoclose'=>true,
			'format'=>'yyyy-mm-dd',
],
		
])->label('end time')?>

<?=$form->field($edu_3,'university') ?>
<?=$form->field($edu_3,'department')?>
<?=$form->field($edu_3,'degree')?>
<?=$form->field($edu_3,'teacher')?>

<?=Html::submitButton('Submit')?>
</div>
    没有找到数据。
您需要登录后才可以回答。登录 | 立即注册
hiccup_yin
见习主管

hiccup_yin 枣庄

注册时间:2016-01-24
最后登录:2016-06-19
在线时长:6小时0分
  • 粉丝5
  • 金钱75
  • 威望30
  • 积分435

热门问题