0

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?

7
  • Ever thought about the usage of parameters? Also, do you really need a new view. php for every user? Commented Aug 23, 2018 at 5:57
  • you can use routes Commented Aug 23, 2018 at 6:01
  • Yeah..How can i achieve the same Commented Aug 23, 2018 at 6:02
  • Well in controller just get the user type and then according to user type make a switch statement that switch view according to user type. Got any idea. Commented Aug 23, 2018 at 6:09
  • You can get answer here also stackoverflow.com/questions/30723525/… Commented Aug 23, 2018 at 6:13

2 Answers 2

0

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.

Sign up to request clarification or add additional context in comments.

6 Comments

this way is not a good choice..I need a customized controlller for different clients(this only a view change,In some clients have so many functional changes)
no, no need to customize it. as you can see that you just need to customize or set your client account to display it's load view. your controller will be the same just follow the condition inside the controller.
The main thing is that the new changes are not affected our already created features thats why i suggest the same.
I mean a customized folder for every client(customized controller,model,view).The count is based on clients.All extra client requirements wont affected core files
Yes... you can customize the folder inside the condition. example: $this->load->view('view1', $this->data); you can change that inside.
|
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.