這是我在模型規則中的代碼... ............................. .................................................. ..............................................CJuiDatePicker始終在數據庫中保存當天
array('dataMedicao', 'type', 'type' => 'date', 'message' => '{attribute}: is not a date!', 'dateFormat' => 'yyyy-MM-dd'),
array('dataMedicao', 'default',
'value' => new CDbExpression('NOW()'), //automatically add the current date in mysql feild
'setOnEmpty' => true, 'on' => 'update'),
array('date_created,date_modified', 'default',
'value' => new CDbExpression('NOW()'),
'setOnEmpty' => false, 'on' => 'insert'),
................................................ .................................................. ............................
protected function beforeSave() {
$this->dataMedicao = new CDbExpression('NOW()');
return parent::beforeSave();
}
protected function afterFind() {
$this->dataMedicao = date('Y-m-d', strtotime($this->dataMedicao));
return TRUE;
}
............... .................................................. .................................................. ........
這是我在表單代碼...
<?php echo $form->labelEx($model, 'dataMedicao'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name' => 'dataMedicao',
'attribute' => 'dataMedicao',
'value' => $model->dataMedicao,
// additional javascript options for the date picker plugin
'options' => array(
'showAnim' => 'fold',
'dateFormat' => 'yy-mm-dd',
),
'htmlOptions' => array(
'style' => 'height:20px;'
),
));
?>
<?php echo $form->error($model, 'dataMedicao'); ?>
.............................. .................................................. ...........................................
在我的數據庫日期設置爲0000-00-00,當我列出他們,他們將設置爲1970-01-01 ...然後在更新我使用DatePicker設置日期來更新字段,但它總是獲取更新到當前我們的日期...如何獲取DatePicker中設置的日期以及如何將其保存在我的數據庫中? 感謝您的全力幫助
解決了......謝謝! ;) – 2014-10-30 10:23:26