A
A
Alexander Ivanov2018-02-25 20:46:15
Yii
Alexander Ivanov, 2018-02-25 20:46:15

How to get data from a column in a table?

There is a User table in the database. At authorization there is a request to this table. It is necessary to pull out the data from the "status" column and pass it to the template.
Data that comes:
skrinshoter.ru/s/250218/n0WcWr33?a
Controller:

/**
     * Login action.
     *
     * @return Response|string
     */
    public function actionLogin()
    {
        if (!Yii::$app->user->isGuest) {
            return $this->goHome();
        }

        $model = new LoginForm();
        if ($model->load(Yii::$app->request->post()) && $model->login()) {
    
      print_r($model);
      die();
      
            return $this->goBack();
        }
        return $this->render('login', [
            'model' => $model,
        ]);
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton, 2018-02-25
@alexsteadfast

echo $model->user->status;
This works if the app\models\LoginForm model declares an association with User.

public function getUser()
{
    return $this->hasOne(User::class, ['id' => 'user_id']);
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question