问题
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
回答1:
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.
回答2:
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.
来源:https://stackoverflow.com/questions/22879270/declare-global-array-in-codeigniter-to-access-between-different-functions