Declare global array in codeigniter to access between different functions

纵饮孤独 提交于 2019-12-25 03:03:16

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!