how to determine that the site is running on production or developer environment?
|
Sep '15 |
3 |
750 |
0 |
I'm not sure what you mean. I think there are many ways of determining or checking if you are on a production or development environment. I would do this way I would check what $_SERVER['SERVER_NAME'] returns and if i decided that localhost is development environment and $_SERVER... returns 'localhost' is development f.e. localhost i could set the standard $config variable value into $config->development=true (after config is initialised or during initialisation with ("development" => ($_SERVER['SERVER_NAME'] =="localhost")?true:false) or something like this ) This in turn (i assume you register the config in the di variable as Phalcon tutorials show) could be used in your controller action this way (if you wanted) $this->config->development or you could use differnt settings for database for di. Some other users could give you some better tips.
If you set the config variable as i suggested (you don't need to but you then have the config variable accessible in controller, models, etc) you could do something like this
$di->set('db', function () use ($config) {
if ($config->development===true) {
if (strtolower($config->database->adapter)=="mysql") {
return new DbAdapter(array(
'adapter' => $config->databasedev->adapter,
'host' => $config->databasedev->host,
'username' => $config->databasedev->username,
'password' => $config->databasedev->password,
'dbname' => $config->databasedev->dbname
));
}
} else {
if (strtolower($config->database->adapter)=="mysql") {
return new DbAdapter(array(
'adapter' => $config->database->adapter,
'host' => $config->database->host,
'username' => $config->database->username,
'password' => $config->database->password,
'dbname' => $config->database->dbname
));
}
}
});
Your other services (like autoloader autoloading directories/classess, namespaces) could be easily switched in a similar way.