• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How can I change an array element in the $config array from a Controller?

#1
[eluser]warpspasm[/eluser]
Good Morning!

In application/config/my.php

I have a

$config['my_element'] = 'abcdef';

From a controller in /application/controllers/my_cont.php

function mine()
{
// I'd need to set $config['my_element'] again
// I tried this but it did not work:

global $config;

$config['my_element'] = 'ghijk';

// But it did not work, $config['me_element'] stayed the original value in another function!

}

How can I do this?
Thank you

#2
[eluser]PhilTem[/eluser]
http://codeigniter.com/nightly_user_guid...onfig-item

#3
[eluser]memVN[/eluser]
You should code as:
In controller: $this->config->set_item('your_element', 'new value');

Good luck

#4
[eluser]CroNiX[/eluser]
Changing config values via the config library does NOT write the data to the config file. It will only be changed for that request (in memory) and then get set back to the original value when the config library gets reinitialized and reloads the config files on the next request.

If you need a permanent change, or to pass the change to another server request, you'll have to extend the config library so it will write changes to the config.php file, or use sessions, or use a cookie, or create a config system using the database, or.... but the config library won't make permanent changes.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.