这是我在模型规则中的代码... ............................. .................................................. ..............................................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