Let's start by having a look at how the User
model is used in Yii.
You can open the file located at /models/User.php
.
The first thing to notice is that the User
class extends from a generic Yii Object
class and implements IdentityInterface
:
// User.php namespace app\models; use yii\base\Object; use yii\web\IdentityInterface; class User extends Object implements IdentityInterface { // ...
The yii\base\Object
class is the parent class of all classes, which implements the concept of virtual attributes, with the use of dynamically invoked getters and setters, while yii\web\IdentityInterface
provides the signature for methods we need to implement in our class to provide the authentication mechanism.
You will also notice by the private property $users
that the model does not connect to a database; instead, it holds all the authentication data within the class itself. This has been done on purpose by the Yii developers, in order to have everything working without additional...