Ho bisogno, ancora una volta, del vostro aiuto;
in una tabella (event) ho 2 campi (event_date e event_dateExpiration), questi 2 campi prendono come input 2 date tramite il datePicker.
Il problema sorge nel momento in cui io voglio salvare la data del secondo campo, infatti il primo campo(event_date) riesce a salvare la data nel formato in cui desidero, mentre il secondo(event_dateExpiration) mi salva la data in questo modo: 30-11-1999 pur avendo inserito un altra data.
passiamo alla sostanza, questo é il codice:
model
protected function afterFind() {
list($y, $m, $d) = explode('-', $this->event_date);
$mk = mktime(0, 0, 0, $m, $d, $y);
$this->event_date = date('d-m-Y', $mk);
list($a, $b, $c)=explode('-', $this->event_dateExpiration);
$abc=mktime(0,0,0,$a,$b,$c);
$this->event_dateExpiration=date('d-m-Y', $abc);
return parent::afterFind();
}
protected function beforeSave() {
list($d, $m, $y) = explode('-', $this->event_date);
$mk = mktime(0, 0, 0, $m, $d, $y);
$this->event_date = date('Y-m-d', $mk);
list($a, $b, $c)=explode('-', $this->event_dateExpiration);
$abc=mktime(0,0,0,$a,$b,$c);
$this->event_dateExpiration=date('d-m-Y', $abc);
return parent::beforeSave();
}
_form
<?php
echo '<p style="margin-bottom:5px;">Data</p>';
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'event_date',
'value'=>$model->event_date,
'language'=>'it',
'options'=>array(
'showAnim'=>'fold',
'mode'=>'datetime',
'dateFormat' => 'dd-mm-yy', // save to db format
),
'htmlOptions' => array(
'style' => 'height:20px;'
),
));
?>
<?php
echo '<p style="margin-bottom:5px;">Scadenza</p>';
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'event_dateExpiration',
'value'=>$model->event_dateExpiration,
'language'=>'it',
'options'=>array(
'showAnim'=>'fold',
'mode'=>'datetime',
'dateFormat' => 'dd-mm-yy', // save to db format
),
'htmlOptions' => array(
'style' => 'height:20px;'
),
));
?>
Grazie in anticipo!