0

I want to declare a global variable in my model and will use it accordingly.
syntax below is just example how I want to use it, may not be proper syntax. But I want to know proper syntax for this to implement.

global $stddata

call to 1st function via ajax:

add a array of data to this global variable.

global $stddata = array(1=>"a",2=>"b");

after user triggers some event call to 2nd function via ajax:

Access the array stored in global variable above.

echo $stddata
Cœur
  • 37,241
  • 25
  • 195
  • 267
Kaushil Rambhia
  • 195
  • 2
  • 6
  • 19
  • Your global statement is incorrect, you will need to use `define('foo', 'bar');` for *assignment* and use `global $var` to import a variable into the current scope. Also being a global variable does not mean it will persist beond one request, it simply sets the scope that it can be accessed. – AlexP Apr 05 '14 at 10:03

2 Answers2

0

Your question is similar to :

Code Igniter - best place to declare global variable

or How to declare global variable in CodeIgniter 2.2?

Try this, you might get solution.

Community
  • 1
  • 1
Nehil Mistry
  • 1,101
  • 2
  • 22
  • 51
  • i tried using codeigniter flashdata but it is not able to take data as array..i need some other method..because many times my data will be huge.. – Kaushil Rambhia Apr 05 '14 at 10:42
0

I would suggest you put it in core controller. You should create MY_Controller.php file in application/core folder and use wanted array as you wish. It will be in any controller that extends MY_Constroller class.

Tpojka
  • 6,996
  • 2
  • 29
  • 39