php – Yii中的Datepicker将数据存储为yy MM d格式
发布时间:2020-12-13 14:08:51 所属栏目:PHP教程 来源:网络整理
导读:我有一个表单,其中输入字段是这样的 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'=
我有一个表单,其中输入字段是这样的
<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; } 将以上代码添加到您的模型中.它应该工作. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |