This is my first question here and I beleive the question is not exists already 🙂 I searched but without succes.
Ok, I have a next problem.
I need some idea how to do a users permissions in admin panel.
I want to have a super admin, admin and operator.
Anyone of this wiil have different privileges.
Super admin wiil have all privileges, admin some and operators some but not all will have the same privileges.
I need a back-end logic for this.
How to do that without many if statements so my code looks nice?
I use a Smarty template engine and oop php writen by my own.
I wiil assign with Smarty privilege but what next?
Can anyone give me idea or some example code?
Thanks!
Using MVC this is a relatively simple task. Create the different roles in a table called
permissionsand then another table calleduser_permissionswhich connects theuser_idto thepermission_id. Then create a function, maybe in a class calledusercalledhas_role(). That function accepts two arguments: permission alias and eventually a user id.If you want to avoid calling functions in the view, you can in your controller save different variables, which are passed to the view, such as:
If you’re only displaying some content to admins, you could do something like this in your views:
However, if you’re having admin-only pages, simply putting
will do the trick. All of this is of course doable without the MVC-part, it however becomes way cleaner with it.