• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Implementing Navigation Bar

I am unsure how to do the following in CI:

- I have three pages: home, portfolio, and search.
- At the top of each of these pages resides a navigation bar.
- The navigation bar contains a log-in.
- The home page contains a registration form, as well.

The way I have it (not) working is that I have created three controllers for each of the pages, and four views (one for each page, and one for the navigation). However, I have now come to the following problem:

When a user logins on the home page, they have to be redirected to the home page but the navigation bar has to be updated to show that they are logged in. The same problem for each of the other pages...

I'm not sure if this makes sense - but I suppose an easier question would be what is the best pattern to implement a common navigation bar containing a log-in form in CI?

(If it helps I'm using TankAuth.)

I created a simple template library, which is autoloaded. In that library, it automatically generates the header view, login panel view (shows user details if logged in, login form if not), sidebar view and footer view. The template library figures out if the user is logged in or not and loads the appropriate view. That view just looks at the session and sees if their info is present and shows the form if not logged in, or their details and link to their profile if they are. Then, in my controllers, all I have to do is just pass the template library the main content view (using 3rd parameter of load::view() TRUE) and it does the rest. So, the controller is only worrying about what its primary task is and leaves the rest up to the template library.

If you are new to CI as I was 4 months ago, the very best resource I can suggest for the newbie is a book written by Tom Meyer "Professional Codeigniter". The approach CroxNix recommends is also laid out in Meyers Book at Amazon. It is perfect, but it might be hard to visualise without it written out. Don't be put off by the fact that Meyers book was written with CI 1.7. The differences are minor, the logic is identical.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.