[英]CJuiDatePicker not saving date in db
我正在嘗試在yii中的表單上使用CJuiDatePicker。 該小部件看起來不錯,但提交后,除日期字段外,所有其他表單字段值都存儲在數據庫中。 可能是什么問題?
看我的代碼:
<div class="row">
<?php echo $form->labelEx($model,'date'); ?>
<?php //echo $form->dateField($model,'date');
$this->widget('zii.widgets.jui.CJuiDatePicker',array(
'model'=>$model,
'name'=>'date',
'attribute'=>'date',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
'dateFormat' => 'yy-dd-mm',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
<?php echo $form->error($model,'date'); ?>
</div>
檢查模型中的“日期”字段
我在模型中使用這段代碼
public function beforeSave()
{
if( $this->data )
{
$this->data = date('Y/m/d H:i',strtotime(str_replace('/','.',$this->data) ));
}
return parent::beforeSave();
}
感謝您的貢獻。 我能夠解決它。 這是修改后的代碼:
<?php //echo $form->dateField($model,'date');
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'date',
'value'=>$model->date,
//additional javascript options for the date picker plugin
'options'=>array(
'dateFormat'=>'yy-mm-dd',
'showAnim'=>'fold',
'debug'=>true,
'datepickerOptions'=>array('changeMonth'=>true, 'changeYear'=>true),
),
'htmlOptions'=>array('style'=>'height:20px;'),
));
?>
<?php echo $form->error($model,'date'); ?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.