如何在代码点火器框架中定义动态全局变量。
问题描述:
How to define a dynamic global variable in code-igniter framework.
I am using Geo-Location tracking api, which tracks the country of the user based on user's IP address. I need to set the value of this global variable dynamically depending on the country code returned from the API.
what is the best way to achieve this ?
如何在代码点火器框架中定义动态全局变量。 p>
我正在使用地理位置跟踪API,它根据用户的IP地址跟踪用户所在的国家/地区。 我需要动态设置此全局变量的值,具体取决于从API返回的国家/地区代码。 p>
实现此目的的最佳方法是什么? p> DIV>
答
In your case, You can store the value in session like this
$newdata = array(
'country' => 'Nepal',
);
$this->session->set_userdata($newdata);
And again retrieve the session value like this
$country = $this->session->userdata('country');