Welcome Guest, Not a member yet? Register   Sign In
session - different views
#1

[eluser]Unknown[/eluser]
Hello,

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
#2

[eluser]InsiteFX[/eluser]
Check your session in your controller then load the nav view that you need in your controller.

Credit Author: Adam Griffiths Auth 1.06
Code:
<ul id="navigation">
&lt;?php
if(logged_in())
{
?&gt;
  <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>
&lt;?php
}
else
{
?&gt;
  <li>&lt;?php echo anchor('login', 'Login'); ?&gt;</li>
  <li>&lt;?php echo anchor('register', 'Register'); ?&gt;</li>
&lt;?php
}

?&gt;
</ul>
#3

[eluser]bigbusty[/eluser]
you should do that in your controller
#4

[eluser]Unknown[/eluser]
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.




Theme © iAndrew 2016 - Forum software by © MyBB