codeigniter,显示动态仪表板

时间:2018-01-16 05:43:27

标签: php codeigniter class inheritance dynamic

我正在使用CodeIgniter框架。我想根据用户类型显示仪表板。我在不同的文件中有3种不同的用户类型和3种不同的类。

我想在一个类中继承所有三种类的get。

基本上,我这样做是为了隐藏URL中的类名

以下是代码示例。

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);
    }

}

我也想调用此类中其他三个类中的函数。

2 个答案:

答案 0 :(得分:0)

您可以使用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');
    }
}

答案 1 :(得分:0)

更改您的索引功能如下所示,然后尝试:

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); 
        }
}