I’m working on a personal CMS and I’ve got a problem. I wanted to define access levels such as CAN_DELETE_THREAD, CAN_EDIT_MESSAGE or CAN_CREATE_THREAD as binary flags, but I don’t know how a function ‘has_flag’ would work. For example, if I took a user from the db and wanted to check if he can edit messages, how would I go around doing that?
Thanks!
You could create a
permissionsdatabase table, and apermissions_userstable that joins permissions to users, and then check on a per-page basis if the logged-in user can view that page.Imagine you have a
Usermodel, and a permission with an ID of 1:Your
hasPermission()method could be as simple as:Obviously you’ll need to adjust this to fit your application.