• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
session - different views


I'm a student who is not really experienced yet with webdev/php/ci and Ive been looking for help in existing topics but since i'm not native English it's something a bit harder to understand certain things. So I prefered starting my own question so the advice I (hopfeully) get would be easier to understand.

For a school project I'm trying to use the CI framework while learning PHP aswell. I'm getting the picture with the basics, I created a simple login/reg functionality to start with, with a few controllers, views and a User model. I currently have my header and footer view split up from the content views (each page is a view). When I login, I'm correctly directed to the members view. But there my issue starts...

I currently have no idea how (and where) I have to work with the session to show a different header when logged in, so I can add extra functionaltiy/links in the menubar. For continuity reasons i currently use some statements in my views (if no session, show 'login', if session, show 'logout' , to give a quick example) but this is not the correct way ofcourse.

I've tried to find it myself to do something with the load->views so the correct header shows but my tries fail each time.

Anyone who has the best (codeigniter/mvc) way of implementing this?

Thanks in advance

Check your session in your controller then load the nav view that you need in your controller.

Credit Author: Adam Griffiths Auth 1.06
<ul id="navigation">
  <li>&lt;?php echo anchor('admin/dashboard', 'Dashboard'); ?&gt;</li>
  <li>&lt;?php if(user_group('admin')) { echo anchor('admin/users/manage', 'Manage Users'); } ?&gt;</li>
  <li>&lt;?php echo anchor('logout', 'Logout'); ?&gt;</li>
  <li>&lt;?php echo anchor('login', 'Login'); ?&gt;</li>
  <li>&lt;?php echo anchor('register', 'Register'); ?&gt;</li>


you should do that in your controller

Avoiding the if in the view is indeed my intention.

Currently i only know to have an if-else with the load->views. If i'm in the session I load the headermembers_view, and if not, the regular header_view.

but i do repeat this in every controller for every page.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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