BaseController __construct |
Hi all,
Been using CI4 for a while now and my project is really nicely established and going really well. I wanted to check something that's been bothering me for a while though, As I cant find any information on this. I have a base controller (code stripped down) <?php namespace App\Controllers; class BaseController extends Controller { protected $session; protected $helpers = []; protected $data = []; public function __construct() { // start session if ($this->session == null) { log_message('debug', 'BaseController In __construct starting session service'); $this->session = Services::session(); } } I have several sub controllers all coming off this <?php namespace App\Controllers; class Dashboard extends BaseController { ... } When visiting my sub controllers my logging shows as such DEBUG - 2021-01-18 17:27:50 --> BaseController In __construct starting session service INFO - 2021-01-18 17:27:50 --> Session: Class initialized using 'CodeIgniter\Session\Handlers\FileHandler' driver. . And whenever I call a route via url it always runs everything in __construct. My question is, Is this normal behavior? Do I need to create a session service for every call to the controllers? Or Should I be able to start a session once (perhaps with a time duration) and have it use the same session? Thanks in advance guys!
This is how I do my BaseController.
PHP Code: <?php Also you can always call the session helper. PHP Code: $item = session('itemName'); What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
thanks, thats really interesting. Im going to try that session_status() == PHP_SESSION_NONE.
Still seems to always spin a session. Surely if I just made a request my session shouldn't die once I get a response? |
Welcome Guest, Not a member yet? Register Sign In |