(09-21-2018, 06:16 AM)kilishan Wrote: My suggestion: don't worry about loading the session globally. First - that means that if the session isn't needed it isn't loaded which can be good for performance and some security things, IIRC. Second - whenever you first call the service, or use the the service() helper method, the session will be automatically initialized and ready for use.
Code:
// These all ensure session is initialized:
$session = \Config\Services::Session();
session('key');
session()->get('key');
session()->set('key', $value);
Hi Kilishan. What do you advise for running a db query inside a function in a helper file?
I created a custom helper file and put it in the Helpers/mycustom_helper.php
In this file, I want to create a function say,
Code:
function get_some_stats() {
/// I suppose I can do this -> $db = \Config\Database::connect();
// but if there are 20 different functions, then I'd have to do that in all function repeatedly
}
Am I correct? Just clarifying.