Welcome Guest, Not a member yet? Register   Sign In
Display different views depending on whether user is logged in - Best way?
#1

[eluser]Dave S[/eluser]
Forgive me if this has been asked before. I have searched unsuccessfully for an answer before posting this.

I am trying to figure out the best way to display different views based on whether the user is logged in or not.

For example, in my header or sidebar, I want to list some features. If the person is logged in, they get access to those features. If not, they are redirected to a login / register page when they click. Also, in the header, display a small login form or a 'Welcome, username' message depending on their status.

I am very new to CI and having a hard time wrapping my head around some of the concepts. I have been learning php but most of my code was very linear.

These are some of the ideas I had about how to do this:
1) In every controller, check if they are logged in and pass html in a string to the view for the header.
2) In every controller, check login and pass a variable to the view ($logged_in) then do the logic in the view to decide which code to display. (if ($logged_in) display one thing else... etc)
3) Have 2 versions of header or sidebar views. One for logged in users and one for guests, and have the controller call the appropriate view depending on status.

Are any of these reasonable solutions or am I totally missing something? Any thoughts / ideas are greatly appreciated. Sorry for the long-winded post!


Messages In This Thread
Display different views depending on whether user is logged in - Best way? - by El Forum - 05-21-2008, 12:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB