Configuring Your Application
An Introduction to Configuration with Wax
Configuring your application should be easy and extensible. For this reason you'll notice that for setting up PHP Wax applications we've chosen the easy to use and easy to read YAML format.
If you've got your first application at the ready opening up the file app/config/config.yml will give you an example of how to use YAML for configuration.
What you see inside that file is some basic configuration for a standard Wax application. One of the first things you'll need to change if you want to create database driven applications is the database settings.
Working with Multiple Environments
The best thing about using a framework like PHP Wax is that it encourages you to work in a much more efficient manner. When creating web applications you want deploying your application to have as few points of failure as possible. Hence using different environments is a great idea, you can have different settings for your development, testing and production environments which means that when you put an application live everything just works.
The Default Configuration
The pre-set settings in the app/config/config.yml file are primarily used for the database setup. Of course you will need to change these to reflect your specific settings.
Using Your Own Settings
Of course the app/config/config.yml file can be used to store as much additional configuration as you need. Simply add to the bottom of the file. For single settings you can do something like the following:
google_api_key: 'ABCDEFGHIJKLMNOP01234567890'
default_postcode: 'SW1 4AA'
Those settings can be retrieved in your application by doing the following:
Config::get("google_api_key");
Config::get("default_postcode");
For more complex setups you can use YAML's easy to understand nesting. Take the following as an example:
users:
fred:
username: 'fred'
password: 'secret'
email: 'fred@exaple.com'
joe:
username: 'joe'
password: 'secret'
email: 'joe@exaple.com'
Now we have a very basic user list stored in the configuration. Getting the info back is easy too, to access different levels of config PHP Wax uses a simple path system. So calling the following:
Config::get("users");
will return an array of users each of which also contains an array of settings. By being more specific you can call either:
Config::get("users/fred");
Config::get("users/fred/email");
which will get you either an array of Fred's settings or in the second instance Fred's email address.
Installing SYCK will improve the speed of reading YAML files greatly, which is a benefit on busy production servers.
