CodeIgniter Forums
Best practices/place for setting session data - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter Archived (from EllisLab) (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Best practices/place for setting session data (/thread-25551.html)



Best practices/place for setting session data - El Forum - 12-16-2009

[eluser]Jonas G[/eluser]
Hi

I am currently setting some session data based on geoip data. In my master view template, the very first line is
Code:
$this->betscout->preflight()

preflight() checks to see whether or not sessions like "country" and "timezone" is already set, and if not, sets them.

What i'm looking for is a better place or better practice to do this. I have been trying to make a pre_controller hook for this, but since this cannot get an instance of ci it doesn't cut it for me.

What is the best practice/place to do this kinda thing?


Best practices/place for setting session data - El Forum - 12-16-2009

[eluser]n0xie[/eluser]
Maybe in the construct of MY_Controller?


Best practices/place for setting session data - El Forum - 12-16-2009

[eluser]jedd[/eluser]
I echo n0xie's suggestion.

If you head into the [url="/wiki/FAQ"]FAQ[/url] and look at one of the first questions answered there, about repeating lumps of code, you'll see a few suggestions. The [url="/wiki/MY_Controller"]MY_Controller[/url] approach is certainly one of the easiest and most common ways of implementing this kind of functionality. Unsurprisingly, it's in the FAQ because it's asked about so frequently.


Best practices/place for setting session data - El Forum - 12-16-2009

[eluser]Jonas G[/eluser]
It works perfectly - thank you!