Yii中的Datepicker将数据存储为yy MM d格式

New*_*ser 6 php mysql datepicker yii

我有一个表单,其中输入字段是这样的

  <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> 
Run Code Online (Sandbox Code Playgroud)

我已将此表单保存在模型文件中.它是这样的

    protected function beforeSave()
  {
    $this->due_date=date('Y-m-d', strtotime(str_replace(",", "", $this->due_date)));
    return TRUE;
  }
Run Code Online (Sandbox Code Playgroud)

CJuiDatePicker用于保存日期选择器中的数据.它示出了在时在d毫米日格式的时间节省,但是当我要更新日期是在YY MM d format.If我改变beforeSave()的日期格式示出的形式,它被存储的日期format in 0000-00-00 values.No其他日期值正在存储.有人可以告诉我我做错了吗?任何帮助和建议都将非常适合.

boo*_*dev 8

试试这个:

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;
}
Run Code Online (Sandbox Code Playgroud)

将以上代码添加到您的模型中.它应该工作.