How can I access which environment is installed in CodeIgniter?

I am new to CodeIgniter. I found that CodeIgniter uses the following function in index.php to manage multiple environments

define('ENVIRONMENT', 'development'); 

to determine the environment.

My question is: how can I get which environment is installed in index.php inside my controllers?

+6
source share
2 answers

ENVIRONMENT defined in index.php , which is the pipeline each CI application file, you can access anywhere, for example, a model, view, controller, library

 echo ENVIRONMENT; 
+12
source

In your index.php file try something like this:

 if ($_SERVER['HTTP_HOST'] == 'dev' || $_SERVER['HTTP_HOST'] == 'localhost') { define('ENVIRONMENT', 'development'); } elseif ($_SERVER['HTTP_HOST'] == 'staging.example.com') { define('ENVIRONMENT', 'staging'); } else { define('ENVIRONMENT', 'production'); } 

Obviously set it up with values โ€‹โ€‹that make sense to you. However, this will set the ENVIRONMENT based on where the application is running, automatically.

+2
source

Source: https://habr.com/ru/post/974414/


All Articles