Welcome Guest, Not a member yet? Register   Sign In
creating a structure
#1

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?
proof that an old dog can learn new tricks
Reply
#2

(This post was last modified: 03-08-2022, 12:44 AM by ikesela.)

u can try like this:

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

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?
proof that an old dog can learn new tricks
Reply
#4

(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?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB