Change a config item permanently |
[eluser]vaxis[/eluser]
Hi guys, what's the best way to change a config item permanently? I tried the set_item but it set that item only for that block of code. Another question: For basic application settings like app_name, app_version, company_name and so on is better using a config file or using a db table? Thanks for attention.
[eluser]Twisted1919[/eluser]
Save your config into database and use the items from there : Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
[eluser]erik.brannstrom[/eluser]
The config library works using arrays specified in the configuration files, meaning they are hard-coded. As such, they are not meant to be updated directly from your application. If you absolutely need to do this you'd have to create your own class that can write to these files yourself, however I wouldn't recommend it. This sort of brings us to your second question. Any data that you expect to be changing dynamically (i.e. depending on user actions in the application) should be stored in a database. Other values that very rarely change (such as the name of a company) can be stored in a configuration file. If you still have questions, I believe it would make it easier if you told us a bit more about what you want to be able to do. Anyway, I hope this helped!
[eluser]InsiteFX[/eluser]
Code: -- InsiteFX
[eluser]vaxis[/eluser]
[quote author="erik.brannstrom" date="1273269264"]The config library works using arrays specified in the configuration files, meaning they are hard-coded. As such, they are not meant to be updated directly from your application. If you absolutely need to do this you'd have to create your own class that can write to these files yourself, however I wouldn't recommend it. This sort of brings us to your second question. Any data that you expect to be changing dynamically (i.e. depending on user actions in the application) should be stored in a database. Other values that very rarely change (such as the name of a company) can be stored in a configuration file. If you still have questions, I believe it would make it easier if you told us a bit more about what you want to be able to do. Anyway, I hope this helped![/quote] I made an application.php config file inside the config folder were are stored my application config info like app_version and stuff like this. How can i access this file and change the config[] array items values? Thanks again for answers
[eluser]Genki1[/eluser]
Using CI 2.0.2, when I try to implement Twisted1919's code by calling the method load_db_items() from the __construct(), like this: Code: public function __construct() I receive: Quote:Fatal error: Class 'CI_Controller' not found in system/core/CodeIgniter.php on line 231 Is there any way to solve this? My goal is to set config variables at startup using values from a table so that they are available globally.
[eluser]InsiteFX[/eluser]
Because you need to place this code in your ./application/config/config.php file Code: /*
[eluser]Genki1[/eluser]
I did as you suggested and still receive the same error. When I add this code... Code: function __autoload($class = 'MY_Config') // specified the name of my class file I still receive this error: Quote:Fatal error: Class 'CI_Controller' not found in system/core/CodeIgniter.php on line 231 Any suggestions?
[eluser]InsiteFX[/eluser]
1) You do not specify the name like that it searches the directory! 2) Did you save the controller as ./application/core/MY_Controller.php
[eluser]Genki1[/eluser]
I really appreciate your help but so far I'm not having any success. I have the following: 1. In ./application/config/config.php, I have added your code to the bottom of the file: Code: function __autoload($class) 2. I have created ./application/core/MY_Controller.php with this code: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 3. I have created ./application/controllers/welcome.php with this code: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); When I run index.php/welcome/show_value, I see: Quote:TEST_ID =(no value is displayed) Can you see what I am doing incorrectly? I've spent a few hours at this and it's pretty frustrating. Again, my goal is to set config variables at startup using values from a table so that they are available globally. |
Welcome Guest, Not a member yet? Register Sign In |