yii - EJuiDateTimePicker value is not saved to database -
i using ejuidatetimepicker extension date , time picker in yii framework. have downloaded ejuidatetimepicker , placed under protected\extensions\jui
views:
$this->widget( 'ext.jui.ejuidatetimepicker', array( 'model' => $model, 'attribute' => 'todo_datetime', 'value' => $model->todo_datetime, 'options' => array( 'dateformat' => 'dd-mm-yy', 'timeformat' => 'hh:mm:ss',//'hh:mm tt' default ), ) );
action:
if(isset($_post['todo'])) { $model->attributes=$_post['todo']; if($model->save()) $this->redirect(array('view','id'=>$model->id)); }
problem:
the value of saved in database table 0000-00-00 00:00:00 it's not taking value of datetime picker.
edited:
model validation
return array( array('todo_text, todo_datetime, priority, status', 'required'), array('priority, status', 'numerical', 'integeronly'=>true), // following rule used search(). // please remove attributes should not searched. array('todo_text, todo_datetime, added_on, priority, status', 'safe', 'on'=>'search'), );
well, nothing strange, should use same date format in widget , in database, :
- in widget :
dd-mm-yy hh:mm:ss
- in database :
yyyy-mm-dd hh:mm:ss
you can deal common problem using getter/setter or beforesave/afterfind, here simple example using getter/setter :
in model :
public $datetimeincomeformat = 'yyyy-mm-dd h:mm:ss'; public $datetimeoutcomeformat = 'dd-mm-yy h:mm:ss'; public function getdatetime() { return yii::app()->dateformatter->format($this->datetimeoutcomeformat, cdatetimeparser::parse($this->todo_datetime, $this->datetimeincomeformat)); } public function setdatetime($datetime) { $this->todo_datetime = yii::app()->dateformatter->format($this->datetimeincomeformat, cdatetimeparser::parse($datetime, $this->datetimeoutcomeformat)); }
this create datetime
virtual attribute can use in widget. don't forget add attribute in model validation rules.
http://www.yiiframework.com/doc/guide/1.1/fr/topics.i18n#date-and-time-formatting
Comments
Post a Comment