CodeIgniter Forums
Using a var on every site - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Using a var on every site (/showthread.php?tid=58383)



Using a var on every site - El Forum - 06-08-2013

[eluser]Unknown[/eluser]
Hello,

i have a question. I use to the Session on every Page to check if it is an user.

Code:
$data['session'] = $this->session->userdata('logged_in');


Do i need to insert it on every page? Or ist there a workaround?




Using a var on every site - El Forum - 06-08-2013

[eluser]jairoh_[/eluser]
no need to set that in a $data array to access that in the view, you can call the session anytime, anywhere.


Using a var on every site - El Forum - 06-10-2013

[eluser]Unknown[/eluser]
How can i use it?




Using a var on every site - El Forum - 06-10-2013

[eluser]Pert[/eluser]
Example for a view file
Code:
<? if ($this->session->userdata('logged_in') === true) : ?>
   User is logged in.
<? else : ?>
   User is not logged in.
<? endif ?>



Using a var on every site - El Forum - 06-11-2013

[eluser]boltsabre[/eluser]
Check/assign your session variable in your "MY_Controller" and use:
Code:
$this->load->vars()

It will then be available in every view.

If you don't have a "MY_Controller" yet, simply research it on google, there are heaps of blog posts, threads on here and stackoverflow about this subject.