Welcome Guest, Not a member yet? Register   Sign In
Multiple admin areas & user identification - best approach?
#1

I am completely new to CodeIgniter, so please bear with me. 

To better understand and learn how CodeIgniter works, I am currently building a sample job board application with a login area using Ion Auth. The idea here is to have a super administrator, who has complete access to edit and manage users, posts, settings etc. and a normal user group, that can post and edit only their own jobs and profile details.

With this in mind, I would like to show different admin-areas with different functions to the different user groups; one for the super-admin and one for the normal users.

My question now is, how to organize these two admin-dashboards.

I currently use a single controller "Dashboard.php" to basically load different menu-views depending on the users status (admin vs non-admin):


PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

class 
Dashboard extends MY_Controller
{
 
   function __construct()
 
   {
 
       parent::__construct();

 
       // Load authentication library
 
       $this->load->library('ion_auth');

 
       // Check user status
 
       if (!$this->ion_auth->logged_in())
 
       {
 
           redirect('auth/login');
 
       }
 
   }

 
   public function index()
 
   {
 
       if ($this->ion_auth->is_admin()) {
 
           $this->load->view('common/header');
 
           $this->load->view('dashboard/top_nav_admin');
 
           echo 'This is the administrators page';
 
           $this->load->view('common/footer');
 
       } else {
 
           $this->load->view('common/header');
 
           $this->load->view('dashboard/top_nav_user');
 
           $this->load->view('dashboard/index_view');
 
           $this->load->view('common/footer');
 
       }

 
   }

 

I am not sure if this is a good idea or if it is better to have a unique controller for every user group, also in order to define different methods for each group. I don't want to repeat much code regarding the views in the admin-area (i.e. basically same design but different menus).


Also, another question concerns how to identify a specific user once he or she is logged in to the admin-area in order to only show his posts / user details.

Is there a way to get the user ID and for instance save it in a session or what is the best approach here?

Thanks for your feedback.
Reply


Messages In This Thread
Multiple admin areas & user identification - best approach? - by Neo - 10-30-2016, 07:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB