如何在CodeIgniter中分隔具有相同名称的控制器功能

I'm using CodeIgniter HMVC. I have an educational web application for different clients.

I need a customized controllers for every client. We need to provide different views and functionalities for different clients but only the condition is that, call the same url.

For example, I'm using modules,In my controller name is Test.php. In that controller have a function name view():

    function view(){
       $this->load->view('view', $this->data);  
    } //The thing is that,each client need different views (view.php)

I want the same URL for all clients (http://test.com/test/view).

I have an idea, set a default controller(or a customized controller) and the actual controller. First click on the link, check if the function exist in the default controller then execute the same otherwise will go to the actual controller function.

Is this possible?

In your case, i can suggest to use $this->session->userdata('user_type').

something just like this...

function view(){
    if($this->session->userdata('user_type') == 'Client1'){
        $this->load->view('view', $this->data);  //specify load view for client1
      }
    elseif($this->session->userdata('user_type') == 'Client2'){
        $this->load->view('view', $this->data);  //specify load view for client2
     }
} 

hope it will helps you.

You will need to use some user information to select the correct view for the user. The first argument of the $this->load->view function is the file to load. Be sure to save the information required for this purpose on the user's session.

Define the following in a Trait or base Controller class to use in all user controllers.

function view() {
    // optionally have a function generate $view or create it in the constructor
    // OR as a user specific filename use something like this
    // $view = 'view' . $this->session->userdata('test_view_suffix');
    if ($this->session->has_userdata('userdir')) {
        // in a user specific directory
        $view = $this->session->userdata('userdir');
    } else {
        $view = 'default';
    }
    // append the filename to the directory.
    $view = $view . '/view';
    $this->load->view($view, $this->data);
}

Define your route using a similar method.

$route['test/view'] = function () use (&$_SESSION) {
    $controller = $_SESSION['userdata']['controllerprefix'].'test';
    return $controller.'/view';
};