您可以分配值$模型 - > TIME_START直接在控制器打电话之前渲染..
,所以你的问题可以在controllerAction使用PHP载体作用的分配,需要安装价值管理在actionCreate
public function actionCreate()
{
$model = new MyModel();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
// assign the the date and time of the server that the code runs on.
$model->time_start = date("d-m-Y H:i:s");
return $this->render('create', [
'model' => $model,
]);
}
}
,或者如果你需要一个特定的时区
public function actionCreate()
{
$model = new MyModel();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->redirect(['view', 'id' => $model->id]);
} else {
// assign the the date and time of the server that the code runs on.
//
$my_date = new DateTime("now", new DateTimeZone('America/New_York'));
$model->time_start = $my_date;
return $this->render('create', [
'model' => $model,
]);
}
}
PH P在服务器上运行而不是您的电脑。它将使用服务器时间,除非您以不同的方式说明。你将不得不把时间从PC发送到PHP脚本。然后它可以计算出在'日期选择器'中使用的时间 –