2. Overivew
Objective
Learn how to set different environments in the
configuration file.
Requirements
Understanding of the configuration file
Estimated Time
7 minutes
http://www.prodigyview.com
3. Follow Along With A Code
Example
1. Download a copy of the example code at
www.prodigyview.com/source.
2. Install the system in an environment you feel
comfortable testing in.
3. Proceed to examples/system/Environments.php
http://www.prodigyview.com
4. Environments
Environments are a specified configuration to use based
on the current system environment.
In ProdigyView, configurations can be set to certain
environments. An example of usage is having different
database connections used based upon the server being
used.
When you understand how to set up environments, you
can also begin to use them in other areas, such as
configurations based upon a user.
http://www.prodigyview.com
5. Setting up Connections
To start this tutorial, we are going to set up to database
connections, one for development and one for production.
1. Production Connection
2. Development Connection
6. Add Configuration
Once we have our configurations set up, we can add
them with an environment set. Every configuration as a
key used for saving and accessing the data.
1. Configuration key 2. Data associated with key 3. Environment
7. Retrieving Environment
Variables
Once the environments are saved, they can be retrieved
by calling the environment it was saved as.
1. Key used to save the environment 2. Environment
8. Setting Our Default
Environment
Our next step is to set the default environment. There are many ways to the set
server environment.
$_SERVER[‘ENV’]
$_SERVER[‘SERVER_NAME’]
In NGINX and FastCGI, you can set a custom variable in the fastcgi_params
In Apache, you can set a custom environment variable in the htaccess file
In our example, we are going to use the HTTP_HOST to decide our environment.
9. Configuration
Now it’s time for initializing the configuration class with our
environment. This will create a default environment when
adding and retrieving configurations.
Initialize with environment
10. Retrieving Our Configuration
The last step is retrieving the configuration. Because we
set the environment in the initialization, we no longer need
to specify it when retrieving the configuration.
Retrieve configuration with only the key
11. Review
1. Set a configuration with
PVConfiguration::addConfiguration method.
2. Retrieve a set configuration using
PVConfiguration::getConfiguration method.
3. An environment can be explicitly set when adding and
retrieving configurations.
4. Setting an environment in PVConfiguration::init will create
a default environment in which you will no longer need a
explicitly set the environment when adding or retrieving
data.
http://www.prodigyview.com
12. More Tutorials
For more tutorials, please visit:
http://www.prodigyview.com/tutorials
www.prodigyview.com