Ok, this is the weirdest thing I ever encounter. I am not understand yet about Yii framework. But today, I don’t know this is somekind of bug or what. To summary, I found out that CDBAuthManager->clearAuthAssignments() doesn’t clear the tables if I run on Firefox or Opera. But it does delete the table if I try it on Chrome.
To explain why like that, maybe I will tell how I code.
Today I learn how to use RBAC to authorizing in my web application. So I code like this:
//In protected/controller/SiteController.php
public function actionLogin()
{
....
if($model->validate() && $model->login()){
$this->actionBuildAuth();
...
}
....
}
//in protected/components/SiteController.php
public function actionBuildAuth()
{
$auth=Yii::app()->authManager;
$auth->clearAll();
//create operations
//Users
$auth->createOperation ('listUser', 'Menampilkan users');
...
//task
$task = $auth->createTask('manageUser');
$task->addChild('listUser');
...
$role = $auth->createRole('manager');
$role->addChild('reportInventoryOpname');
...
$auth->save();
}
//in protected/components/UserIdentity.php
public function authenticate()
{
...
}else{ //If validation success
$this->errorCode = self::ERROR_NONE;
....
$this->_id=$users->id;
$auth=Yii::app()->authManager;
if(!$auth->isAssigned($users->type,$this->_id))
{
if($auth->assign($users->type,$this->_id)){
Yii::app()->authManager->save();
}
}
}
...
}
At first I didn’t realize there is wrong step on my above code. So it assign user at first, later call actionBuildAuth() which it do $auth->clearAll();
So here is the weird one. According to the code, calling $auth->clearAll() should make the table of “assignmentTable” empty. That’s mean the $auth->assign() function that I called in authenticate() should be gone too…
But in reality I test it by login on Firefox and Opera, it doesn’t empty.
Only in Chrome it does empty.
So why it can be like that?