• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
passing the same variables to all the views (to handle login status)

#1
[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?

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

#3
[eluser]mah0001[/eluser]
http://davidwinter.me.uk/articles/2009/0...deigniter/

or google codeigniter MY_Controller

#4
[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.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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