Looking for more information on how to do PHP the right way? Check out PHP: The Right Way

Gonzalo Ayuso's Blog:
Using PHP classes to store configuration data
Jan 10, 2011 @ 17:57:39

Gonzalo Ayuso has a new post to his blog today looking at how he uses PHP classes to store configuration information for easier retrieval.

In my last projects I'm using something I think is useful and it's not a common practice in our PHP projects. That's is the usage of a plain PHP’s class for the application's configuration. Let me explain it. Normally we use ini file for configuration. [...] There are many standard options. Why I prefer a different one then? I like plain PHP classes because the IDE helps me with autocompletion. The usage is quite simple.

His example uses a standard class to store the configuration values, one that can be loaded into a project and lets you call the configuration values statically. He gives two examples of how this is helpful in a standard IDE with autocompletion.

tagged: class configuration data ini xml yaml parseinifile

Link:

Eirik Hoem's Blog:
Simple config management for PHP
May 30, 2008 @ 12:54:50

In a new post to his blog today, Eirik Hoem gives an example of using the parse_ini_file function to work with .ini files as configuration for your application.

When doing complex applications it's often nice to have some sort of system for handling settings. PHP has a nice function called parse_ini_file which can be used to create a basic but still usable setting file feature. A simple class which loads the configuration file and offers some methods to retrieve the values for a given key is all that's needed.

His example code gives a sample ini file with database connection information and a MyConfigClass that parses the file and can get or set values in it.

tagged: parseinifile configuration management example

Link:


Trending Topics: