Welcome Guest, Not a member yet? Register   Sign In
Will CI Let Me Redirect to another Controller?
#1

[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.
#2

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

You should use:
redirect('instructor');
#3

[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?
#4

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

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

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




Theme © iAndrew 2016 - Forum software by © MyBB