(09-21-2018, 04:35 AM)happyape Wrote: I looked at the documentation, https://bcit-ci.github.io/CodeIgniter4/l...-a-session, which says,
Code:
To access and initialize the session:
$session = \Config\Services::session($config);
Am I supposed to put this code in the constructor of every Controller class where I need to manipulate session data?
I found that I can also use start session using this helper
but again I need to declare that in all files before I can use session.
I need to know the same for db and custom common functions helper file.
$db = \Config\Database::connect();
All I am trying to find out if I should be placing these in a common file? Or perhaps, declaring in each file is the suggested practice???
Regards.
With the DB connection you better use functions in your controllers and models.
The helpers use them for external libraries of a third party that do not need connection to the DB.