authManager called from console don't work


(Pellicanipasquale) #1

Hi all, I’ve a console controller with an action for generate user (for test) my User model has an afterSave method which after saving based on the assigned role creates a related model, if I try to dump this -> \Yii::$app->authManager->getRolesByUser($this->id) it return me an empty array ! where am i wrong ? Thanks


(Andro) #2

Are you sure your user has roles assigned?
Sounds like you just saved the records to the db.
Where do you assign the user?
Check, if $this->id isn’t empty at the time when you are calling getRolesByUser().

Do you use the PhpManger or DbManager for RBAC?


(Pellicanipasquale) #3

I’m main role (admin) I use DbManager