2

Is there any way that we can update the value of config file and save these values into config file.

For example, I have:

   $config['base_url']  = 'http://localhost.com';
   $config['test'] = '';

I want to change the value of $config['test'] $this->config->set_item('test','something'); and save this value into config file. so, my config file should be

  $config['base_url']   = 'http://localhost.com';
  $config['test'] = 'something';

Thanks.

Sml004
  • 495
  • 1
  • 7
  • 15
  • 1
    **$this->config->set_item('test','something');** will itself set the value of 'test' to 'something' at run-time. You don't need to **save** it again. – Dr. Dan Aug 10 '12 at 06:29
  • at run-time, it is OK. but if I want to save the file. Is it possible? – Sml004 Aug 10 '12 at 06:31
  • You can but I am wondering why you want to do that. – Dr. Dan Aug 10 '12 at 06:33
  • for example, I have a blog name which the default value "My Blog". then if the administrator change this blog name to "Something else", so that I need to save the file. – Sml004 Aug 10 '12 at 06:34
  • So if there is only one blog and assuming administrator which can change the blog name also has the access to config.php file, he can simply manually edit the blog name in the config.php file? – Dr. Dan Aug 10 '12 at 06:38
  • check this out http://stackoverflow.com/questions/2237291/reading-and-writing-configuration-files and http://php.net/manual/en/function.parse-ini-file.php – TigerTiger Aug 10 '12 at 07:11
  • 6
    Why not use a database for this functionality? – cchana Aug 10 '12 at 09:28
  • that's Ok. I will use db – Sml004 Aug 14 '12 at 02:59

1 Answers1

2

You might be better off using a hook that pulls this data from your database (as suggested by cchana). This way you can easily update it without compromising security of your config file.

TotaliNZ
  • 21
  • 2