Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8025637
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:13:45+00:00 2026-06-04T23:13:45+00:00

Not sure if it’s global per se, but what I need is a variable

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T23:13:46+00:00Added an answer on June 4, 2026 at 11:13 pm

    If you want to import a variable from the global scope, you need to use the global keyword. For example:

    class SomeClass {
        public function SomeFunction() {
            global $adsIDvar; // now it is imported from the global scope
        }
    }
    

    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:

    class AdHelper {
        public static $advertiser_id;
    
        public static function getAdvertiserId() {
            if (!isset(self::$advertiser_id)) {
                self::selectAdvertiserId();
            }
    
            return self::$advertiser_id;
        }
    
        protected static function selectAdvertiserId() {
            self::$advertiser_id = ....; // Implement this however you like, random or whatever
        }
    }
    
    // you can call it from anywhere like:
    $adsIDvar = AdHelper::getAdvertiserId();    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Not sure why but I am not getting anything back from the json call.
Not sure entirely what is happening, but I get the following errors from Internet
Not sure if that the right title for the question, but what I'm trying
Not sure what parallel programing means... but I have two thoughts of that Process
Not sure if this counts as programming related, it's a tool that I use.
Not sure exactly what I need to do to make this work, so my
Not sure if I've just missed something but this doesn't work: $(this).children('td.threadtitle a').html('thread title');
Not sure if this is too open-ended of a question for StackOverflow but, I'm
Not sure where to post this, but I can't find any information anywhere and
Not sure what's up. DEBUG mode is set to be on, and everything else

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.