CodeIgniter Forums
creating a structure - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: creating a structure (/showthread.php?tid=81471)



creating a structure - richb201 - 03-07-2022

I am creating a structure in the controller like this  $gtm_data = new stdClass();
Then in MyModel I am trying to populate it like this: $gtm_data->email=$_SESSION['userid'];
phpStorm is complaining about the line where I try to populate the structure. What am I doing wrong?


RE: creating a structure - ikesela - 03-08-2022

u can try like this:

$gtm_data->{'email'} = $_SESSION['userid'];


RE: creating a structure - richb201 - 03-08-2022

Thanks. I modified it like this,
$gtm_data->{'email'}=$_SESSION['userid'];
$gtm_data->{'campaign'}=$_SESSION['$campaign'];
But phpStorm has an issue with the $gtm still.
This code is in the model.
I am creating the gtm_data struct in the main controller with $gtm_data = new stdClass();
How can I just declare gtm_data as a Global so every module has access to it?


RE: creating a structure - kenjis - 03-08-2022

(03-08-2022, 06:27 AM)richb201 Wrote: I am creating the gtm_data struct in the main controller with $gtm_data = new stdClass();
How can I just declare gtm_data as a Global so every module has access to it?

$gtm_data is not a struct, because PHP does not have structs.
$gtm_data is an object.

And it is recommended not to use global variables.
Why don't you pass $gtm_data to the model?