mztest
(Mztester)
1
I am using TimestampBehavior set column created_at to new Expression(‘NOW()’).
return [
[
'class' => TimestampBehavior::className(),
'value' => new Expression('NOW()'),
]
];
After creating a new record, the restful api reutrn ‘created_at’ as
{
"created_at": {
"expression": "NOW()",
"params": []
}
}
But actually I need the value to be ‘2015-02-03 10:10:10’.
How can I get it?
mztest
(Mztester)
2
I create a new CreateAction and refresh the model.
class CreateAction extends \yii\rest\CreateAction
{
public function run()
{
$model = parent::run();
$model->refresh();
return $model;
}
}
The method refresh has to reload the data from database.
I am not sure it’s the best way.
uEhlO4a
(Y Korotia)
3
something like this?
'value' => function () { return \Yii::$app->formatter->asDatetime('now', 'dd-MM-yyyy hh:mm:ss'); }
EndErr
(Enderr)
4
Why not give that possibility to the database if it supports?