php environments
DESCRIPTION
Learn how to customize environments in ProdigyView.TRANSCRIPT
![Page 1: PHP Environments](https://reader033.vdocuments.site/reader033/viewer/2022061218/54828791b47959d30c8b47cf/html5/thumbnails/1.jpg)
Environments
![Page 2: PHP Environments](https://reader033.vdocuments.site/reader033/viewer/2022061218/54828791b47959d30c8b47cf/html5/thumbnails/2.jpg)
OverivewObjective
Learn how to set different environments in the configuration file.
Requirements
Understanding of the configuration file
Estimated Time
7 minutes
http://www.prodigyview.com
![Page 3: PHP Environments](https://reader033.vdocuments.site/reader033/viewer/2022061218/54828791b47959d30c8b47cf/html5/thumbnails/3.jpg)
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
![Page 4: PHP Environments](https://reader033.vdocuments.site/reader033/viewer/2022061218/54828791b47959d30c8b47cf/html5/thumbnails/4.jpg)
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
![Page 5: PHP Environments](https://reader033.vdocuments.site/reader033/viewer/2022061218/54828791b47959d30c8b47cf/html5/thumbnails/5.jpg)
Setting up ConnectionsTo 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
![Page 6: PHP Environments](https://reader033.vdocuments.site/reader033/viewer/2022061218/54828791b47959d30c8b47cf/html5/thumbnails/6.jpg)
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
![Page 7: PHP Environments](https://reader033.vdocuments.site/reader033/viewer/2022061218/54828791b47959d30c8b47cf/html5/thumbnails/7.jpg)
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
![Page 8: PHP Environments](https://reader033.vdocuments.site/reader033/viewer/2022061218/54828791b47959d30c8b47cf/html5/thumbnails/8.jpg)
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.
![Page 9: PHP Environments](https://reader033.vdocuments.site/reader033/viewer/2022061218/54828791b47959d30c8b47cf/html5/thumbnails/9.jpg)
ConfigurationNow 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
![Page 10: PHP Environments](https://reader033.vdocuments.site/reader033/viewer/2022061218/54828791b47959d30c8b47cf/html5/thumbnails/10.jpg)
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
![Page 11: PHP Environments](https://reader033.vdocuments.site/reader033/viewer/2022061218/54828791b47959d30c8b47cf/html5/thumbnails/11.jpg)
Review1. 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
![Page 12: PHP Environments](https://reader033.vdocuments.site/reader033/viewer/2022061218/54828791b47959d30c8b47cf/html5/thumbnails/12.jpg)
www.prodigyview.com
More Tutorials
For more tutorials, please visit:
http://www.prodigyview.com/tutorials