Welcome Guest, Not a member yet? Register   Sign In
How do I handle views loaded based on conditions correctly?
#1

[eluser]Unknown[/eluser]
I am making a system to help manage bills for a friend (and practice at CI). It will require you to login, then once to login it will take you to the overview page showing an overview for each months bill for the current year.

I currently have the controllers layed out like this:
Code:
/auth/         - Brings up the login screen
/auth/do_login - submits the login If successful user goes to /bills/, else the login is displayed again with the validation errors underneath.

/bills/        - Brings up the overview

Now I am wondering how I am supposed to correctly transition between the user correctly logging in -> bill overview. Or, generally speaking, the transition from from the job of one controller to another (My /auth/ controller, from what I understand, is not supposed to have anything to do with displaying a bill overview).

I currently have a redirect setup to go back and forth but it seems there must be a better way.

Thanks,
Thomas
#2

[eluser]bhumes[/eluser]
Redirecting is the way to go.

Code:
$this->load->helper('url');
redirect('bills');
#3

[eluser]Unknown[/eluser]
[quote author="bhumes" date="1307755807"]Redirecting is the way to go.

Code:
$this->load->helper('url');
redirect('bills');
[/quote]

Good to know

Would it be a bad idea to extend the CI controller to include an authorization method that redirects to /auth/ if not logged in? This way I don't have to do

Code:
if (!is_authorized()) {
  redirect();
}

in every controller?

Also, thanks for the reply.

Edit: I just implemented something like that, doing:

Code:
class MY_Controller extends CI_Controller {
    public function __construct() {
        parent::__construct();
        // Add authorization check
        if (!is_authorized()) {
            redirect('auth');
        }
    }
}

seems to work nicely.




Theme © iAndrew 2016 - Forum software by © MyBB