Welcome Guest, Not a member yet? Register   Sign In
Variable Scope - Class Wide Variable
#1

[eluser]Unknown[/eluser]
Hi,

My controller currently has 6 functions (may be more later), and each function creates a variable called $data['categories']. This variable contains the same data each time, so my question is can I set the $data['categories'] variable at the class (controller) level once, and then access it in any of the controller's methods.


Controller Code:
Code:
$data['categories'] = $this->MCategory->getAllCategories();
//this line appears in all functions. How can I create this variable in the controller so
//that it's available throughout all of the controller's functions (and passed to the view
//with $this->load->vars($data)

...      
$this->load->vars($data);
$this->load->view('v_flavour_template');

Many thanks


Messages In This Thread
Variable Scope - Class Wide Variable - by El Forum - 10-03-2009, 07:58 AM
Variable Scope - Class Wide Variable - by El Forum - 10-03-2009, 09:25 AM
Variable Scope - Class Wide Variable - by El Forum - 10-03-2009, 10:38 AM
Variable Scope - Class Wide Variable - by El Forum - 10-03-2009, 12:00 PM



Theme © iAndrew 2016 - Forum software by © MyBB