This is my code in model rules…
…
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;
}
…
This is my code in Form…
<?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’); ?>
…
In my DB dates are set to 0000-00-00 and when I list them they get set to 1970-01-01… Then on update I use the DatePicker to set the date to update the field, but it always gets update to the current date we are on… How do I get the date I set in the DatePicker and how do I save it in my DB?!
Thanks for all the help…