我有一个表单,其中输入字段是这样的
<div class="row">
<?PHP echo $form->labelEx($model,'due_date'); ?>
<?PHP
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
'attribute'=>'due_date','model'=>$model,'options' => array(
'mode'=>'focus','dateFormat'=>'d MM,yy','showAnim' => 'slideDown',),'htmlOptions'=>array('size'=>30,'class'=>'date'),)
);
?>
<?PHP echo $form->error($model,'due_date'); ?>
</div>
我已将此表单保存在模型文件中.它是这样的
protected function beforeSave()
{
$this->due_date=date('Y-m-d',strtotime(str_replace(",","",$this->due_date)));
return TRUE;
}
CJuiDatePicker用于保存日期选择器中的数据.它在保存时以d mm yy格式显示日期,但是当我要更新表格时,日期以yy MM d格式显示.如果我正在更改beforeSave()的dateformat,它将存储日期format in 0000-00-00 values.No其他日期值正在存储.有人可以告诉我我做错了吗?任何帮助和建议都将非常适合.
试试这个:
protected function afterFind(){
parent::afterFind();
$this->due_date=date('d F,Y',strtotime(str_replace("-",$this->due_date)));
}
protected function beforeSave(){
if(parent::beforeSave()){
$this->due_date=date('Y-m-d',$this->due_date)));
return TRUE;
}
else return false;
}
将以上代码添加到您的模型中.它应该工作.