Using session data within a model |
Since you have the $session object in your controller you could also pass it to the model when the model is constructed.
Passing objects to a class constructor as a way of supplying the object's dependencies is a very good habit to have. It's actually considered a best practice, especially if you're going to do unit testing of a class - and you really, really should unit test. Then passing dependencies to an object is pretty much a must. So, one approach is to define a model like this. PHP Code: <?php namespace App\Models; Use the model like this in a controller PHP Code: // other controller code If your model is extending /CodeIgniter/Model then there are a few minor changes, but I bet you get the idea. |
Messages In This Thread |
Using session data within a model - by Fido L Dido - 02-12-2020, 05:14 AM
RE: Using session data within a model - by InsiteFX - 02-12-2020, 01:25 PM
RE: Using session data within a model - by Fido L Dido - 02-13-2020, 04:47 AM
RE: Using session data within a model - by dave friend - 02-12-2020, 06:01 PM
RE: Using session data within a model - by Fido L Dido - 02-13-2020, 04:50 AM
RE: Using session data within a model - by Fido L Dido - 02-13-2020, 08:01 AM
RE: Using session data within a model - by Fido L Dido - 02-13-2020, 09:14 AM
RE: Using session data within a model - by dave friend - 02-13-2020, 09:48 AM
|