CodeIgniter Forums
passing the same variables to all the views (to handle login status) - 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: passing the same variables to all the views (to handle login status) (/showthread.php?tid=29984)



passing the same variables to all the views (to handle login status) - El Forum - 04-28-2010

[eluser]Unknown[/eluser]
Hi!

I want to show in each page (almost each page) a login or logout link like the one in this forum.

I'm organizing my views through django like inherited templates and I'm using dx_auth as authentication library.

How I can accomplish that?
I can for example pass each time a variable data["is_logged"] = True, though it leads to a big code duplication, what's the best solution you've found?


passing the same variables to all the views (to handle login status) - El Forum - 04-28-2010

[eluser]nelson.wells[/eluser]
Create a "secure controller" that extends the base controller, and in the constructor do your if($logged){} check. Then, any controller in which all the methods need to be secured, you will inherit the secure controller instead of the base controller. Make sense?


passing the same variables to all the views (to handle login status) - El Forum - 04-28-2010

[eluser]mah0001[/eluser]
http://davidwinter.me.uk/articles/2009/02/21/authentication-with-codeigniter/

or google codeigniter MY_Controller


passing the same variables to all the views (to handle login status) - El Forum - 04-29-2010

[eluser]mddd[/eluser]
You can 'give' variables to all views using $this->load->vars($array);
Example:
Code:
// set variables
$this->load->vars('name'=>'Pete', 'profilelink'=>site_url('profile/pete'));
// now you can use $name and $profilelink in any view.