[eluser]caen[/eluser]
Hello,
I'm getting started with CodeIgniter (trying to learn the MVC approach to program design, as well as trying to learn how to use a framework), and I want to create a simple application. The basic flow would be
1. Check if the user is authenticated.
2. If the user is
not authenticated, display and process a login form.
3. If the user is authenticated, display a page and process some input.
I've managed to create the authentication code (step 2) and the input processing (step 3), but now I don't know how to go about step 1. I have two ideas, and I want to know if they are good, and how you would improve them.
The first idea is to create an
Index controller which checks to see whether the user is authenticated, and, if he or she is, redirect the user to the controller for step 3. Otherwise, redirect the user to the authentication page. It seems simple enough. The only downside I can see is that I am writing a third controller and that when someone accesses the website, the first thing they get is a redirect (this is particularly painful for a mobile user).
The second idea is to load the controller I wrote for user authentication and have something like
if the user is authenticated, redirect to the controller for step 3; otherwise, go to step 2 inside the constructor. This also seems simple, but I don't know if it is the right approach.
Any thoughts on this matter? I also don't want suggestions for authentication libraries, as I'm just trying to play with the framework, not create anything complex. Thanks in advance!