We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Create development environment

I have a simple flag to set up the development environment.

    'dev_environment' => true, // true or false

This does:

  • Disables cache
  • Show Error
  • etc...

Maybe Phalcon need to implement:

$env = $app->detectEnvironment(
        'local' => new Phalcon\Config([ ... ])
);

or some other way to establish environments.

I would like to know what your settings to create an environment for development and production.

edited Sep '16

set variable environment:

ngnix:

location / {

    fastcgi_param APP_ENV production; 

}

php

 getenv('APP_ENV'); // or
 $_SERVER['APP_ENV'];


40.1k
Accepted
answer

index.php

/*
 *---------------------------------------------------------------
 * APPLICATION ENVIRONMENT
 *---------------------------------------------------------------
 */
define('ENVIRONMENT', isset($_SERVER['APP_ENV']) ? $_SERVER['APP_ENV'] : 'development');

/*
 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------
 */
switch (ENVIRONMENT) {
    case 'development':
        // Notificar todos los errores de PHP
        error_reporting(-1);
        ini_set('display_errors', 1);
        ini_set('log_errors', '1');
        break;

    case 'testing':
    case 'production':
        ini_set('display_errors', 0);
        error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
        break;

    default:
        header('HTTP/1.1 503 Service Unavailable.', true, 503);
        echo 'The application environment is not set correctly.';
        exit(1); // EXIT_ERROR
}

/*
 *---------------------------------------------------------------
 * CONSTANTS
 *---------------------------------------------------------------
 */
define('APP_PATH', realpath('..'));
define('WEB_PATH', realpath('.'));