在codeigniter中声明全局数组以访问不同的函数 [英] Declare global array in codeigniter to access between different functions

查看:132
本文介绍了在codeigniter中声明全局数组以访问不同的函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的模型中声明一个全局变量并相应地使用它。下面的
语法只是示例,我想如何使用它,可能不是正确的语法。但我想知道适当的语法来实现它。

  global $ stddata 

通过ajax调用第一个函数:



向这个全局变量添加一个数据数组。

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

在用户通过ajax触发第二个函数的某些事件调用之后:

访问上面存储在全局变量中的数组。

  echo $ stddata 


解决方案

我建议你把它放在核心控制器中。
您应该在application / core文件夹
中创建MY_Controller.php文件,并根据需要使用wanted数组。
它将在任何控制器中扩展MY_Constroller类。


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

解决方案

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.

这篇关于在codeigniter中声明全局数组以访问不同的函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆