I'm trying to implement my first RBAC system:
I'm getting to this part:
In oficial documentation, they have an example with a username:
$auth->assign('adminRole', 'userA');
$auth->assign('adminRole', 'userB');
However, I did found that, on my case, the ID will work instead.
$auth->assign('adminRole', '8');
$auth->assign('adminRole', '9');
Why did the ID work, and not the username? I presumed it was because, somewhere, we have overwrite the getId()
method from UserIdentity
.
However, after keep following the documentation, and the Yii code, I notice that the assign()
method, does not accept a child of CUserIdentity
, it uses, IWebUser
interface, instead.
I then go to CWebUser
and I notice the getId()
method has the following:
/**
* Returns a value that uniquely represents the user.
* @return mixed the unique identifier for the user. If null, it means the user is a guest.
*/
public function getId()
{
return $this->getState('__id');
}
I keep following this, and I end up on a $_SESSION[$key]
and now I'm confused.
What id is that? I presume is the primary key of my user database table.
But how does CWebUser knows about my user database table (that's called tbl_site_user
) btw.
The only configuration I have that do relates the user, and the authorization is this, on my main config file:
'authManager'=>array(
'class'=>'CDbAuthManager',
'connectionID'=>'db',
),
Where did Yii got the ID on $auth->assign
second argument?