/** * @inheritdoc */ public function init() { if ($this->logicalFormat === null) { $format = $this->type . 'Format'; $pattern = Yii::$app->formatter->{$format}; } else { $pattern = $this->logicalFormat; } if (substr($pattern, 0, 4) === 'php:') { $this->_phpLogicalFormat = substr($pattern, 4); } else { $this->_phpLogicalFormat = FormatConverter::convertDateIcuToPhp($pattern, $this->type); } if ($this->physicalFormat === null) { $driverName = Yii::$app->db->driverName; if (isset(static::$dbDatetimeFormat[$driverName])) { $pattern = static::$dbDatetimeFormat[$driverName][$this->type]; } else { $pattern = static::$dbDatetimeFormat['default'][$this->type]; } } else { $pattern = $this->physicalFormat; } if (substr($pattern, 0, 4) === 'php:') { $this->_phpPhysicalFormat = substr($pattern, 4); } else { $this->_phpPhysicalFormat = FormatConverter::convertDateIcuToPhp($pattern, $this->type); } parent::init(); }
public function actionIndex() { $model = new DynamicModel(['created_at' => time()]); $model->attachBehavior('format', ['class' => DateConverter::className(), 'logicalFormat' => 'php:d/m/Y', 'physicalFormat' => 'php:time', 'attributes' => ['createAt' => 'created_at']]); var_dump($model->createAt); $model->createAt = '10/59/2015'; var_dump($model->created_at); print_r([$model->created_at, time()]); echo str_repeat('=', '5'); $model->created_at = time(); print_r([$model->createAt, $model->created_at]); die(__METHOD__); // return $this->render('index'); }
public function behaviors() { return [['class' => DateConverter::className(), 'type' => 'date', 'logicalFormat' => 'php:d-m-Y', 'attributes' => ['FrDate' => 'fr_date', 'ToDate' => 'to_date', 'SDate' => 'sdate']]]; }