Issue
I have a form,in which the input field is like this
<div class="row">
<?php echo $form->labelEx($model,'due_date'); ?>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker',
array(
'attribute'=>'due_date',
'model'=>$model,
'options' => array(
'mode'=>'focus',
'dateFormat'=>'d MM, yy',
'showAnim' => 'slideDown',
),
'htmlOptions'=>array('size'=>30,'class'=>'date'),
)
);
?>
<?php echo $form->error($model,'due_date'); ?>
</div>
I have made save this form in model file.It is something like this
protected function beforeSave()
{
$this->due_date=date('Y-m-d', strtotime(str_replace(",", "", $this->due_date)));
return TRUE;
}
CJuiDatePicker is used to save the data from Date picker. It is showing the date in d mm yy format at the time of save but when I am going to update the form the date is showing in yy MM d format.If I am changing the dateformat of beforeSave(), it is storing the date format in 0000-00-00 values.No other date values are storing. Can some one tell me where I am doing wrong? Any help and suggestions will be highly appriciable.
Solution
Try this:
protected function afterFind(){
parent::afterFind();
$this->due_date=date('d F, Y', strtotime(str_replace("-", "", $this->due_date)));
}
protected function beforeSave(){
if(parent::beforeSave()){
$this->due_date=date('Y-m-d', strtotime(str_replace(",", "", $this->due_date)));
return TRUE;
}
else return false;
}
Add the above code to your model. And it should work.
Answered By - bool.dev
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.