【发布时间】:2018-06-24 18:44:12
【问题描述】:
我正在使用 CodeIgniter 框架。我想根据用户类型显示仪表板。我在不同的文件中有 3 种不同的用户类型和三个不同的类。
我想在一个类中继承所有三种类型的类。
基本上,我这样做是为了在 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);
}
}
我也想调用这个类中其他三个类中的函数。
【问题讨论】:
-
@MittulAtTechnoBrave 我想保持网址不变。像 DASBOARD 因此我这样做是为了隐藏函数所在的类的名称。
-
请仔细阅读我的问题。
标签: php codeigniter class inheritance dynamic