I have an external database for an SMF forum which contains all my users. I can setup Yii so people are able to login with their forum name and password, but I don’t know how to assign each user a role, such as reader, moderator, admin and so on.
What I’d like to do is, create user groups in the forum and then use the user group IDs to assign a user role in Yii.
For instance I have a “content moderator” group within the forum with ID 10 and when people log in, I’d like Yii to take that ID 10 and assign a user role to it based on the ID.
This code should be placed in controller init() method. Or, if you want roles to be available anywhere in your application, you might consider extending CController with your own abstract controller class, placing the code inside it’s init() method, and extending this new class instead of CController: