Book Image

Learning Yii Testing

Book Image

Learning Yii Testing

Overview of this book

Table of Contents (16 chapters)
Learning Yii Testing
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using the User model


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...