• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
global variable in controllers

#1
[eluser]brian88[/eluser]
For my controller, I was wondering how to use the same variable for more than 1 function.
Code:
class Main extends CI_Controller {
  function __construct() {
    parent::__construct();
    $v = "23";
  }

  function index() {
    echo $v; // doesnt work, undefined var
  }
}

#2
[eluser]Learn CodeIgniter[/eluser]
Code:
class Main extends CI_Controller {

  public $v;

  function __construct()
  {
    parent::__construct();

    $this->v = "23";
  }

  function index()
  {
    echo $this->v; // doesnt work, undefined var
  }
}


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.