Welcome Guest, Not a member yet? Register   Sign In
How to start session globally?
#14

(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
Code:
session()->start();
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.
Reply


Messages In This Thread
How to start session globally? - by happyape - 09-21-2018, 04:35 AM
RE: How to start session globally? - by sv3tli0 - 09-21-2018, 04:59 AM
RE: How to start session globally? - by happyape - 09-21-2018, 05:21 AM
RE: How to start session globally? - by happyape - 09-21-2018, 05:34 AM
RE: How to start session globally? - by sv3tli0 - 09-21-2018, 06:10 AM
RE: How to start session globally? - by happyape - 09-21-2018, 06:16 AM
RE: How to start session globally? - by kilishan - 09-21-2018, 06:16 AM
RE: How to start session globally? - by happyape - 09-21-2018, 06:58 AM
RE: How to start session globally? - by happyape - 09-21-2018, 07:36 AM
RE: How to start session globally? - by macruzgi - 11-04-2019, 10:48 AM
RE: How to start session globally? - by macruzgi - 11-04-2019, 01:21 PM
RE: How to start session globally? - by kilishan - 09-21-2018, 09:21 AM
RE: How to start session globally? - by macruzgi - 11-04-2019, 01:29 PM
RE: How to start session globally? - by macruzgi - 11-04-2019, 03:05 PM
RE: How to start session globally? - by macruzgi - 11-05-2019, 07:51 AM
RE: How to start session globally? - by macruzgi - 11-08-2019, 04:17 PM
RE: How to start session globally? - by InsiteFX - 11-05-2019, 05:50 PM



Theme © iAndrew 2016 - Forum software by © MyBB