Welcome Guest, Not a member yet? Register   Sign In
New to CI - Having global variables available to every controller?
#1

[eluser]Bleeding Edge Productions[/eluser]
Hi guys,

I just typed a very long message only to have is disappear into the 'ether', so please forgive the brevity of this replacement one.

I am new to CI (and quite new to PHP). I'm following Blanco and Upton's "CodeIgnter 1.7" book, which quite early on has the controller:


Code:
class Start extends Controller {

  var $base;

  function Start() {
    parent::Controller();
    $this->base = $this->config->item('base_url');
  }

  function hello($name = 'Guest') {
    $data['base'] = $this->base;
    $data['mytitle'] = 'Welcome to this site';
    $data['mytext'] = "Hello, $name, now we're getting dynamic!";
    $this->load->view('testview', $data);
  }

}

..which is great.

BUT, I want $base and to be available to EVERY controller, and ideally don't want to have to instantiate the variable every time - or certainly not have to have a separate function in every controller to populate it. Is this possible (ie have the variable instantiated and populated by default, or at least combine the functions), and if so, is it against best practice or something?

I'm sure there's a simple solution which through inexperience I'm just not seeing Smile Any help would be appreciated!

Many thanks,

Martin


Messages In This Thread
New to CI - Having global variables available to every controller? - by El Forum - 10-05-2010, 07:25 PM



Theme © iAndrew 2016 - Forum software by © MyBB