Welcome Guest, Not a member yet? Register   Sign In
Login system - handling same view that is different for user and guest
#2

[eluser]boltsabre[/eluser]
Yes, check for the logged in/out status MY_Controller, and have all other controllers extend it. You then have a choice of two options:

1. Loading a logged in or out view direct from your controllers depending on the logged in/out status.
2. Load the same view from your controller, but inside that view control what is being displayed to logged in/out users (this is my preference as option one creates 2 views for every page, updating something shared means you have to update it in two places, not very DRY).

To achieve the second option, in MY_Controller you can load the logged in/out status into a variable and load it directly into all views using this line of code

Code:
$this->load->vars($array)
http://ellislab.com/codeigniter/user-gui...oader.html

Then if your views it's a simple matter of displaying / not displaying content to users depending on their status. In MY_Controller, lets say if logged in $logged_in = true; if not logged in $logged_in = false; and that you've loaded it by using the above code snippet. In your view it's now a simple matter of
Code:
<?php if($logged_in): ?>
   // display something for the logged in user
<?php endif; ?>

<?php if(!$logged_in): ?>
   //display something for not logged in user
<?php endif; ?>

<?php if($logged_in): ?>
   //display something for logged in user
<?php else: ?>
   //else display something else
<?php endif; ?>


Messages In This Thread
Login system - handling same view that is different for user and guest - by El Forum - 01-11-2013, 03:08 AM



Theme © iAndrew 2016 - Forum software by © MyBB