php environments

12
Environments

Upload: prodigyview

Post on 05-Dec-2014

1.100 views

Category:

Technology


0 download

DESCRIPTION

Learn how to customize environments in ProdigyView.

TRANSCRIPT

Page 1: PHP Environments

Environments

Page 2: PHP Environments

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

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

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

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

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

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

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

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

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

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

www.prodigyview.com

More Tutorials

For more tutorials, please visit:

http://www.prodigyview.com/tutorials