I want to create a userIdentity custom class according to my specific requirements. Here is the code
<?php namespace app\models; use yii\web\IdentityInterface; use app\models\dbTables\Users; class UserIdentity implements IdentityInterface{ const ERROR_USERNAME_INVALID=3; const ERROR_PASSWORD_INVALID=4; const ERROR_NONE=0; public $errorCode; private $_id; private $_email; private $_role; private $_name; public function findIdentityById($id){ $objUserMdl = new Users; $user = $objUserMdl::findOne($id); $userRole = $objUserMdl->getUserRole($user->user_id); $this->_id = $user->user_id; $this->_email = $user->email_address; $this->_role = $userRole; $this->_name = $user->full_name; return $this; } public function getId() { return $this->_id; } public function getName(){ return $this->_name; } public function getEmail(){ return $this->_email; } public function getRole(){ return $this->_role; } public static function findIdentity($id) { return self::findIdentityById($id); } public function getAuthKey() { throw new NotSupportedException('"getAuthKey" is not implemented.'); } public function validateAuthKey($authKey) { throw new NotSupportedException('"validateAuthKey" is not implemented.'); } public static function findIdentityByAccessToken($token, $type = null) { throw new NotSupportedException('"findIdentityByAccessToken" is not implemented.'); } } ?>
Basically, I have two roles of tables and users, and I want to set specific properties from both tables in yii :: $ app-> user-> identity
When I call the above code, the findIdentity($id) function returns an error for obvious reasons, stating that I cannot call $this in a static funtion. How to set the required properties in a function and return an instance of the userIdentity class from it ?
source share