CodeIgniter Forums
Will CI Let Me Redirect to another Controller? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Will CI Let Me Redirect to another Controller? (/showthread.php?tid=3875)



Will CI Let Me Redirect to another Controller? - El Forum - 10-26-2007

[eluser]scottelundgren[/eluser]
I'm writing an application that requires authentication & authorization. I've written a controller that handles these requirements but now I face a dilemma and need some architectural advice.

Once my "login" controller performs the authentication and authorization routines I'd like to redirect my user into another controller based on their role. What I envision is that these "role controllors" would then load the role models, fetch data and perform the view:
Code:
if ($this->_authenticate() && $this->_authorize()) {
  if ($this->session->userdata('role') == "instructor") {
    $this->redirect('instructor');
  } elseif ($this->session->userdata('role') == "administrator") {
    $this->redirect('administrator')
  } else {
    $data['error'] = "Could not authorize ".$this->session->userdata('username');
    $this->load->view('login_authorize', $data);
  }
} else {
  <!-- snip load the login form snip -->
}

I'm having trouble with my redirects firing. Is this not the "CI" way to accomplish this? what's the better way of making sure they user is logged in and shuffling them off to their respective task screen. It seems like I'm clouding my "login" controller if I write 2 functions for each task to seperately load the models & views for my seperate roles.


Will CI Let Me Redirect to another Controller? - El Forum - 10-26-2007

[eluser]Eric Barnes[/eluser]
I think instead of:
$this->redirect('instructor');

You should use:
redirect('instructor');


Will CI Let Me Redirect to another Controller? - El Forum - 11-01-2007

[eluser]scottzirkel[/eluser]
I have the problem where once I enter into the https section of the site, the redirect() function will take me back to http. Within controllers I can use $this->function_name() and pass variables and whatnot, but I can't leap from controller to controller. Any ideas?


Will CI Let Me Redirect to another Controller? - El Forum - 11-01-2007

[eluser]Eric Barnes[/eluser]
You could always do a standard php header redirect:

header('Location: http://www.example.com/');


Will CI Let Me Redirect to another Controller? - El Forum - 11-01-2007

[eluser]scottzirkel[/eluser]
I actually took walesmd's advice from this thread: http://ellislab.com/forums/viewthread/62566/