简体   繁体   中英

codeigniter, display dynamic dashboard

I am using CodeIgniter framework. i want to show dashboard according to user type. I have 3 different user types and three different classes in different files.

I want to inherit all three types of classes get in one class.

Basically, i am doing this to hide the name of class in URL

Here is a sample of code.

class Dashboard extends CI_Controller {

 public $user_type

    function __construct() {
        parent::__construct();
        if (!$this->session->userdata('id'))  redirect('login');
        //print_r($userData); exit;
        $this->load->model("Dashboard_m");
        $user_type = $this->session->userdata['user_type'];
    }

    public function index()
    {
        if($user_type ==1) {
           admin_dashboard; // show diffent controller which is placed in diffrent file.
        }elseif($user_type ==2) {
           manager dashboard // show diffent dashboard which is placed in diffrent file.
        }else {
           Employee Dashboard // show diffent dashboard witch is placed in diffrent file.
        }

        $data['header']     = $this->load->view('header_v', null, true);
        $data['navmenu']    = $this->load->view('navmenu_v', null, true);
        $data['sidebar']    = $this->load->view('sidebar_v', null, true);
        $data['footer']     = $this->load->view('footer_v' , null, true);

        $this->load->view('dashboard_v', $data);
    }

}

also i want to call functions placed in three other classes in this class.

you can use redirect :

public function index()
{
    if($user_type == 1)
    {
        redirect('admin_dashboard', 'refresh');
    }
    elseif($user_type == 2)
    {
        redirect('manager_dashboard', 'refresh');
    }
    else
    {
        redirect('employee_dahboard', 'refresh');
    }
}

Change your index function as below and try:

public function index()
{
        $data['header']     = $this->load->view('header_v', null, true);
        $data['navmenu']    = $this->load->view('navmenu_v', null, true);
        $data['sidebar']    = $this->load->view('sidebar_v', null, true);
        $data['footer']     = $this->load->view('footer_v' , null, true);

        if($user_type ==1) {
           $this->load->view('admin_dashboard', $data);
        }elseif($user_type ==2) {
           $this->load->view('manager_dashboard', $data);
        }else {
           $this->load->view('Employee_dashboard', $data); 
        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM