Not sure if it’s global per se, but what I need is a variable that is set from within a model that is dynamically generated when the model gets called. However I need to set a variable that is accessible to multiple views being pulled in through the template to use the same variable.
Its an advertisement ID my clients sponsors have multiple ad spots per page example a 486x 60 and a 160×90 spot. But what I am trying to do is when there ID is pulled at random from the bunch I want all my ad spots to be the same sponsor.
Now I have tried going in my header.php view and defining a variable like
$adsIDvar = $this->modelname->sponsorids() and then in every view I have ad placement just using $varIDvar but it doesnt seem that any of the views inherate the variable. I have tried to find information on this but most people looking for a similar notation need hard coded variables like a site title for example.
I need something that can cross the barrier, and I’d prefer to avoid sessions/cookies as I want to avoid dealing with the whole Cookie thing in the UK as a good half of the viewers of the site are from the UK and I’d rather not have to go through the effort of saying this site uses cookies blah blah accept/decline just for this purpose. Besides, if they decline, that puts a kink in my work.
If you want to import a variable from the global scope, you need to use the
globalkeyword. For example:It’s just my opinion but maybe a better approach would be to make a special class just for handling ad ids. I might try something like this: