Codeigniter 4 extend core class process clarification |
An attempt has been made to extend the Codeigniter framework Session class and override function get, instead of replacing the whole Session class / library. This was by following the guide at https://www.codeigniter.com/user_guide/e...re-classes
Steps taken: - A new class has been created at `app/Libraries/Session.php` - Points of note in this file - Added a new namespace: `namespace App\Libraries;`. - Pulled in the Codeigniter framework Session class: `use CodeIgniter\Session\Session as BaseSession;`. - Extended this class in the function head `class Session extends BaseSession`. - Called the parent constructor (not sure if this is required): - ```public function __construct() { parent::__construct($this->driver, $this->config);}``` - Created a function with the same name `public function get` to override the framework version. - As suggested via https://www.codeigniter.com/user_guide/e...re-classes went to the previous section on the same page https://www.codeigniter.com/user_guide/e...re-classes and performed the steps as below: - Ensured the Autoload.php could find the namespace App\Libraries (confirmed via `php spark namespaces`). - An assumption has been made the interface will be implemented by extending the parent class, that implements the interface. - It’s not clear what is meant by `and modify the appropriate Service to load your class in place of the core class.` - As adding the below to `app/Config/Services.php` didn’t appear to do anything, another assuption was made that a new Services.php file might need to be created at `app/Libraries/Config/Services.php` (see below also) - as per https://www.codeigniter.com/user_guide/e...re-classes; however it’s not clear if the content of the class(es) is correct. PHP Code: <?php PHP Code: <?php - The file located at vendor/codeigniter4/framework/system/Config/Services.php has not been modified. - `var_dump('Session_get');die;` has been added to `app/Libraries/Session.php` but is not being hit. Can anyone possibly assist here please?! |
Messages In This Thread |
Codeigniter 4 extend core class process clarification - by Semsion - 04-08-2024, 12:07 PM
RE: Codeigniter 4 extend core class process clarification - by kenjis - 04-08-2024, 03:15 PM
RE: Codeigniter 4 extend core class process clarification - by Semsion - 04-09-2024, 09:19 AM
RE: Codeigniter 4 extend core class process clarification - by kenjis - 04-10-2024, 07:29 PM
RE: Codeigniter 4 extend core class process clarification - by Semsion - 04-11-2024, 04:44 AM
RE: Codeigniter 4 extend core class process clarification - by kenjis - 04-11-2024, 04:50 PM
RE: Codeigniter 4 extend core class process clarification - by Semsion - 04-15-2024, 09:38 AM
RE: Codeigniter 4 extend core class process clarification - by kenjis - 04-15-2024, 05:26 PM
RE: Codeigniter 4 extend core class process clarification - by Semsion - 04-17-2024, 05:08 AM
|