Integrate Symfony2 in AppFog
Some AppFog platforms are PHP framework ready. For these ones, you can create a new config file in order to detect the platform database parameters for your instance when deploying your Symfony2 web app and then integrate it as resource in the config.yml file imports section.
// Parameters for deployment in AppFog
$vcap = getenv("VCAP_SERVICES");
if ($vcap)
{
// Environment variable VCAP_SERVICES exists
$services_json = json_decode($vcap, true);
$mysql_config = $services_json["mysql-5.1"][0]["credentials"];
// Set Symfony2 parameters
$this->container->setParameter('database_host', $mysql_config["host"]);
$this->container->setParameter('database_name', $mysql_config["name"]);
$this->container->setParameter('database_user', $mysql_config["user"]);
$this->container->setParameter('database_password', $mysql_config["password"]);
}
If VCAP_SERVICES environment varible exists we change every database parameter for our app instance. If it does not exist the default database parameters in parameters.yml will be used.
Written by Santos Jiménez
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#