Reputation: 290
I am new to codeigniter , In my program i want a variable need to be accessed by multiple controllers, It's not a constant variable, value of variable changes ,
Sorry , My mistake I want to store a JSON object to be precise
Pls help me to figure this out.
Thanks in advance.
Upvotes: 1
Views: 388
Reputation: 20737
Since you are using CodeIgniter and sessions then something like this could work out for you:
set it
$someJSONobject = 'JSON';
$this->session->set_userdata('GLOBAL_JSON', $someJSONobject);
retrieve it
$someJSONobject = $this->session->userdata('GLOBAL_JSON');
echo $someJSONobject->subitem;
Make sure you are storing sessions in a DB if you go with this option because Cookie space is VERY limited
Even if you are not using CodeIgniters' session implementation then you can do something quite similar in native PHP:
$someJSONobject = 'JSON';
$_SESSION['GLOBAL_JSON'] = $someJSONobject;
Upvotes: 0
Reputation: 868
Appending on Rooneyl's solution you may want to save that value on session which is easier to access from all end
Upvotes: 0
Reputation: 7902
You can create a base controller with an attribute for your variable, then have your controllers extend that base controller.
Upvotes: 2