Jump to content

Prefered Config Settings Methods.


gevans

Recommended Posts

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  ???

Link to comment
Share on other sites

Lol, putting your db credentials in your db  :D

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.

Link to comment
Share on other sites

Lol, putting your db credentials in your db  :D

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.

Link to comment
Share on other sites

Lol I can't read.

 

And yeah. However, you could still use a flat file with some skills :P

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';

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 ).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.