I am trying to find a way to create a menu in Codeigniter that displays different options based on the access level of the user i.e. If they’re an admin, and editor or just a normal user. Some of their options will overlap.
I’ve considered adding an if statement to the view, but this isn’t very good MVC. I’ve also considered creating a multi-dimensional array within a controller that sets the menu options based on the user access level.
I’d really appreciate ideas and opinions.
Each of your user accounts should have a set of roles, i.e. Dashboard, Sales, Payments, Products, Product Add/Edit, Product Delete, Reports, etc. (you can use Ion Auth’s groups as roles). Then you create a view which will display the menu and you will pass the logged user roles to that view. Then you go through all roles and compare them to the user roles. If the user has a role to see a specific page then you add a link to that page in the menu.
That’s it 🙂
Hope I helped.