Reputation: 13
I am working on a project which is built with CodeIgniter and uses Tank Auth authentication library(modified version to work with user roles) . Everything is working fine but I want to show different content and/or functions to different user groups.
For example, I have 2 roles Admin & User and the site uses a dashboard which both users can currently access. For now we will use navigation lists, I want too have a navigation list for the user (home, about, other user features etcetera) and I would like to have a navigation for admins. But the admin can see both lists and the user can only see the user list.
The roles are currently set by a role_id in the database so role_id 1 = Admin and role_id 2 = User. I was wondering is there a easy way to do this in the view file for my dashboard?
The reason I want to do it this way is I don't want to have to login into two different panels when I want to use admin or user features on my site.
Upvotes: 1
Views: 1120
Reputation: 393
I'm not familiar with CodeIgniter or Tank Auth but in plain PHP you could do the following:
<?php
if (role_id == 1) {
?>
<!-- Admin HTML here -->
<?php }
if (role_id == 1 || role_id == 2) {
?>
<!-- User HTML here -->
<?php } ?>
The admin can see both the user and admin HTML but the user can see only the user HTML
Upvotes: 0