【发布时间】:2016-02-11 21:14:13
【问题描述】:
我正在使用这个功能
public $year;
public $month;
public $day;
protected function afterFind() {
parent::afterFind();
$dob = explode('/', $this->dob);
$this->year = $dob[0];
$this->month = $dob[1];
$this->day = $dob[2];
return $this;
}
protected function beforeSave() {
$this->dob = $this->year .'/'. $this->month .'/'. $this->day;
}
<div class="col-md-2 dayForm noPadding">
<?php
echo $form->textFieldGroup(
$user,
'day',
array(
'widgetOptions' => array(
'htmlOptions' => array(
'placeholder' => 'DD'
)
)
)
);
?>
</div>
<div class="col-md-3 monthForm ">
<?php
echo $form->dropDownListGroup(
$user,
'month',
array(
'widgetOptions' => array(
'data' => array('01' => 'January' , '02' => 'February' , '03' => 'March' , '04' => 'April' , '05' => 'May' , '06' => 'June' , '07' =>'July' , '08' =>'August' , '09' =>'September' , '10' =>'October' , '11' =>'November' , '12' =>'December'),
// 'data' => 'Jan','Feb';
'htmlOptions' => array(
'class' => 'col-md-3 ',
'prompt' => 'Choose month',
),
)
)
);
?>
</div>
<div class="col-md-2 yearForm noPadding">
<?php
echo $form->textFieldGroup(
$user,
'year',
array(
'widgetOptions' => array(
'htmlOptions' => array(
'placeholder' => 'YYYY',
'class' => 'col-md-3',
)
)
)
);
?>
</div>
将出生日期字段拆分为 3 个单独的字段。很简单,用户输入日期、月份和年份,并以正确的格式输入。我遇到的问题是,当用户去更新整个 dob 字段时,所有字段都显示在 year textfieldgroup 中,不太好。
如何在退出时将其重新展开,以便所有相应的字段都出现在它们的 textfieldgroups / dropdownlist 组中?
【问题讨论】:
-
remove
return $this;in after find 并将parent::afterFind()放在函数的最后一行 -
所以完全删除 return $this 并在最后添加 parent::afterfind() ?尝试了这个,它没有改变。有什么想法吗?
-
你能发布控制器代码吗?
-
我应该在控制器中寻找什么?我有 actionCreate、actionView 和 actionUpdate
-
您遇到问题的操作,即我认为的更新