- Site Template
- WordPress Theme
- Blogging Theme
- CMS Theme
- Marketing Template
- eCommerce Theme
- Forum Theme
- Flash Template
- PSD Web Template
- .NET Script
- PHP Script
- HTML5 Code
- CSS Style
- Edge Animate Template
- Muse Template
- TypeEngine Theme
- Static Site Generator
- Sketch Template
CodeCanyon PHP Configuration System 7199251
PHP Script \ Miscellaneous
Class \ Configuration \ Oriented \ Options \ Object \ Notation \ Config \ Array
PHP Script - PHP Configuration System 7199251 by afflicto @ CodeCanyon
PHP Script \ Miscellaneous
Last Update: 20 March 14; Software Version: PHP 5.3, PHP 5.4, PHP 5.5; Files Included: PHP.
Introducing NeatConfig – The simple way to manage the configuration of your application. Supports multiple environments!
- Store your configurations as simple .php arrays
- Manage multiple environments with ease
- Use array dot-notation to get nested config values
- Includes an example of a static facade
- Well-documented, clean object-oriented code!
Installation & Basic use
This script is one single class, in 1 file. So it should be fairly easy to get started. However, here’s a basic introduction.
Also, I recommend you read through the two example files located in the ‘examples’ directory of the ZIP File, they should get you going pretty quickly.
I assume your application has a file structure similar to this.
To integrate NeatConfig, simply place the Config class somewhere.
Now, create a config directory.
Now, probably the most common kind of configuration is database information, like host, database, password etc. Let’s create a “database.php” file in our new ‘config’ directory.
Now, in your index.php, instantiate (create) a new instance of the Config class. It takes two parameters, the path to our config directory, and the ‘environment’ we’re in. You can leave out the second parameter if you don’t use multiple environments (Like one for production and one for local development).
The path to the config directory can be either a relative path of the script or a full path.
$config = new AfflictoNeatConfigConfig('config');
Remember our database.php configuration file? let’s put some stuff in there. Each config file must return an array. Perhaps our database config looks like this.
'driver' => 'mysql',
'connection' => array(
'host' => 'localhost',
'username' => 'affy',
'database' => 'somedb',
'password' => 'secret',
Now, to get the values from our database.php config, we can do this.
$databaseConfig = $config->get('database');
Note that you can also use array dot-notation to get nested values of the config array, like so.
$password = $config->get('database.connection.password');
Also, if you’re using multiple environments, you can (if you need to) specify that you want a specific environment like so.
$developmentDatabase = $config->get('database', 'development');
That concludes this short introduction to NeatConfig, I hope you like it. If you have any questions or feature requests, be sure to give me a comment.
Most often, some of the configuration is different depending on what environment you’re in, whether on a local development machine, or on a live server somewhere, where some values might be different (like the URL or database).
You should probably keep all your configs in the root of your ‘config’ directory, and override them by creating a folder for each environment in the ‘config’ directory.
Let’s say, for our application, we’re using a different database driver or a different database name/password, let’s create a new folder called ‘local’ in our ‘config’ directory, and create a ‘database.php’ file there as well.
Now, when we initialize $config, we set our current environment in the second parameter.
$config = new AfflictoNeatConfigConfig('config', 'local');
Now, when we request the database config, it will first search for one defined in our ‘local’ directory, then fall-back to the root ‘config’ directory if that specific environment does not override it.
PHP Datatables & jQuery Plugin; Form Class - AJAX, Validation, jQuery & Bootstrap; Class Mutations - Dynamically Add Methods; HTML Layout & Utility Class; Event/Hook class.
Keywords: array, class, config, configuration, configuration class, dot-notation, environment, object-oriented, oop, options, php.
Android, Builder, Business, Clean, Corporate, Creative, Design, Ecommerce, Email, Fashion, Gallery, Image, Iphone, Jquery, Landing, Magazine, Magento, Marketing, Minimal, Mobile, Modern, Multi, Multipurpose, Online, Parallax, Personal, Photography, Plugin, Portfolio, Product, Responsive, Simple, Slider, Social, Store, Template, Theme, Video, Woocommerce, Wordpress
Show all tags
Show all tags
- ThemeForest Module A Minimalist Photography WordPress Theme 19716683
- ThemeForest Cizarua Responsive One Page Portfolio Theme 19692781
- ThemeForest Bekas Responsive WordPress Blog Theme 19680464
- ThemeForest Spin Multipurpose Responsive One page HTML Template 19757452
- ThemeForest Cloudio Hosting Instapage Template 19758859
- ThemeForest Reality Pro Real Estate Responsive Template 19719211
- ThemeForest Let's Play Hockey School & Sport Theme 19638415
- ThemeForest Lutty Personal Blog PSD Template 19670984
- ThemeForest Bizmate One page Portfolio Template 19744099
- ThemeForest Moti App Responsive Landing Page 19751641