D
D
Damir Shaniyazov2021-11-22 17:21:31
Yii
Damir Shaniyazov, 2021-11-22 17:21:31

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,
        ]);
    }


in mysql created_by varchar255 and created_date is datetime

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Bay, 2021-11-22
@shaniyazovdamir

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 question

Ask a Question

731 491 924 answers to any question