Answer the question
In order to leave comments, you need to log in
How to store data in a variable?
Good afternoon! Tell me why the data is not being recorded
public function actionCreate()
{
$model = new Schedule();
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->created_by = Yii::$app->user->identity->username;
$model->created_date = date("Y-m-d H:i:s");
$model->save();
return $this->redirect(['view', 'id' => $model->id]);
}
return $this->render('create', [
'model' => $model,
]);
}
Answer the question
In order to leave comments, you need to log in
Questions
1) Why $model->save() twice? use beforeSave() or Behaviours() (the latter is preferred).
2) what data is not recorded? if you don't know xdebug, try calling var_dump $model->getFirstErrors() after saving;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question