S
S
Sergey2016-07-22 01:09:51
Yii
Sergey, 2016-07-22 01:09:51

Why can't I log in if I redefine the users array in yii2 to exactly the same one?

Greetings gentlemen. Instead of a regular array, I want to use an array from a database. I've done this before in another project and it worked fine, now it doesn't.
To start with the code: Here are
30c3dab70e0d480d8388bc8405affea4.png
some explanations for it:
1. I'm commenting out the standard array.
2. I make a constructor method, from which I call another method, in which I want to override with an array from the database (the second piece of code). Do not ask why not do it right away in the constructor, I have my own atmosphere and tasks (:
3. I override the property $this->users = $users;
Everything is ok, but I see an error when submitting the login form:
267153ff2a2b4fdaa2898aeac54684f3.png
I thought that the array from the database came in a different format, I began to debug it, and for debugging, I simply override it in the getUsers() method with its own standard array (i.e. I use all the code from the first screenshot as in the picture) and exactly the same an error that in the second screenshot when submitting the login form.
The array was redefined because in the controller, when:

$user = new User();
var_dump($user->users); die();

I see the correct array.
Why, it turns out, exactly the same array, if it is redefined - does not work?
What am I doing wrong?
UPD:
These two implementations give the same error when logging in! It seems to be as simplified as possible, what kind of magic?
1:
d7a39a2d67984813b0f153f22a485aac.png
2:
a5cb67c10c2940f1ab04386c178688b3.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2016-07-22
@butteff

use init() instead of a constructor

public function init() {
    $this->getUsers();
    parent::init();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question