gevans Posted May 4, 2009 Share Posted May 4, 2009 Hey guys, This is kind of a poll without a poll enabled, because lets be honest, no one likes polls. But more than a poll this is going to give us a view into the workings of different developers based on their response to the following... I'm making a lot of new classes from scratch to all work beautifully together from a starting main class to easily use anything you could imagine with simple ease. So after calling my first class I can connect to a database, draw a page, upload an image, you name it I'll be able to do it. One thing I haven't decided, which you'd think I would have made my mind up about already is how to lay out my configuration settings, to file or not to file. Currently I used a file called config.php above the root folder containing a multi dimensional array full of settings. I used to define every setting, using an array made no difference really, I just liked it. Now I'm considering putting everything apart from db details into a db table, everything can be loaded on initiating the first class. I just wanted some feedback to see what you guys do in similar situations, how do you store your settings!? So yea kind of a poll ??? Quote Link to comment https://forums.phpfreaks.com/topic/156786-prefered-config-settings-methods/ Share on other sites More sharing options...
Ken2k7 Posted May 4, 2009 Share Posted May 4, 2009 I would store them in a DB table named config. Quote Link to comment https://forums.phpfreaks.com/topic/156786-prefered-config-settings-methods/#findComment-825673 Share on other sites More sharing options...
jackpf Posted May 4, 2009 Share Posted May 4, 2009 Lol, putting your db credentials in your db A tad paradoxical. I'd just use a config file. That's what I do, just shove everything into an array. That way you don't have to use a database unescessarily. If your site is heavily db oriented, it's a bonus, as there'll be less strain on people having to fetch the config settings on every page request amongst everything else. Quote Link to comment https://forums.phpfreaks.com/topic/156786-prefered-config-settings-methods/#findComment-825690 Share on other sites More sharing options...
gevans Posted May 4, 2009 Author Share Posted May 4, 2009 Lol, putting your db credentials in your db A tad paradoxical. Now I'm considering putting everything apart from db details into a db table, everything can be loaded on initiating the first class. Though you do make a good point, I'd just be loading all the settings into an array at the start of each request anyway. But having the settings in a db makes it so much easier if you start adding an admin area to your application, allowing you to upadate settings. Quote Link to comment https://forums.phpfreaks.com/topic/156786-prefered-config-settings-methods/#findComment-825697 Share on other sites More sharing options...
jackpf Posted May 4, 2009 Share Posted May 4, 2009 Lol I can't read. And yeah. However, you could still use a flat file with some skills I personally haven't needed to, since I'm the only person using my site. I just fire up filezilla and edit the file by hand if I want to change somethign. However, forum software such as this keep config settings in a database because they have like 235789234579 settings. But that's because they've got to cater for people who could want different settings, and can't edit the PHP files. So yeah, as long as you're not developing a forum or some huge CMS system or something, you might as well just use a flat file. With an interface, it could be something like this (just wrote it - it's pretty shit but could be adapted) <?php $file = eval(file_get_contents('conf.php')); $config['test2'] = 'new_value'; $fh = fopen('conf.php', 'w+'); fwrite($fh, null); foreach($config as $key => $value) { $value = '$config[\''.$key.'\'] = \''.$value."';\n"; fwrite($fh, $value); } fclose($fh); ?> Then in your config file if you have something like this: $config['test1'] = 'somethign'; $config['test2'] = 'something_else'; Quote Link to comment https://forums.phpfreaks.com/topic/156786-prefered-config-settings-methods/#findComment-825706 Share on other sites More sharing options...
gevans Posted May 4, 2009 Author Share Posted May 4, 2009 Yea, I used to do something very similar when setting a website as online or offline through a simple admin area. I think both methods have their good and bad points. I just can't decide, I might go with a db table just because I've never stored settings in a db before, and it kind of goes hand in hand wityh my whole revamping and going completely OOP to leave my main system as flexible as possible. Quote Link to comment https://forums.phpfreaks.com/topic/156786-prefered-config-settings-methods/#findComment-825718 Share on other sites More sharing options...
Daniel0 Posted May 4, 2009 Share Posted May 4, 2009 I use Zend_Config which has read/write support for PHP arrays, INI files and XML files. Quote Link to comment https://forums.phpfreaks.com/topic/156786-prefered-config-settings-methods/#findComment-825721 Share on other sites More sharing options...
gevans Posted May 4, 2009 Author Share Posted May 4, 2009 I use Zend_Config which has read/write support for PHP arrays, INI files and XML files. I just had a quick look at that. I've never used the Zend Framework, but that does look useful, and I'm sure I could knock out a simple version for myself. Quote Link to comment https://forums.phpfreaks.com/topic/156786-prefered-config-settings-methods/#findComment-825723 Share on other sites More sharing options...
Daniel0 Posted May 4, 2009 Share Posted May 4, 2009 You can just take it out of the framework. ZF can be used as both a library and framework. Quote Link to comment https://forums.phpfreaks.com/topic/156786-prefered-config-settings-methods/#findComment-825730 Share on other sites More sharing options...
gevans Posted May 4, 2009 Author Share Posted May 4, 2009 Oh right, I need to do some reasearch into ZF. Start using some parts through a library. Quote Link to comment https://forums.phpfreaks.com/topic/156786-prefered-config-settings-methods/#findComment-825742 Share on other sites More sharing options...
suncore Posted May 5, 2009 Share Posted May 5, 2009 Plain configuration file ( let's say system/config.php ) is what I prefer - easy to access, does not cause any performance loss ( usually caused by using mysql queries, etc. ) and more or less, easy readable ( in case if it's not a private script ). Quote Link to comment https://forums.phpfreaks.com/topic/156786-prefered-config-settings-methods/#findComment-826847 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.