U
U
ukoHka2017-02-12 23:47:43
Yii
ukoHka, 2017-02-12 23:47:43

How to make simple authorization in Yii2?

The basic version of Yii2 has the simplest authorization with ready-made demo data in the static array $users of the User class. I wrote a function that forms an array in the same format, but with data from the database. But when you try to assign the $users array, the result of the function gives an error . The internet says that static variables cannot be assigned non-static results, but the function is declared as static and still the same error. I also tried to copy the User class from advanced/common/user.php, but it already complains about the missing class. And I don’t even know if it will be easier to use advanced (it’s still complicated for me) or if you can still transfer authorization from there to basic. public static $users = self::getAll();syntax error, unexpected '(', expecting ',' or ';'

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-02-12
@ukoHka

it is possible to transfer from advanced of course.

But when you try to assign the result of the function public static $users = self::getAll(); to the $users array;
- some kind of hell, you are doing something completely wrong. What is the $users array? Why not make a getter:
public function getUsers(){
return $this->getAll();
}

But the strangest thing is what it will give? Give me the full code. And why do you need this basic?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question