Reputation: 219
I am new to CodeIgniter. I have found that, in order to manage multiple environments, CodeIgniter uses the following function in index.php
define('ENVIRONMENT', 'development');
to define the environment.
My question is, how can I get which environment set at index.php inside my controllers?
Upvotes: 10
Views: 12406
Reputation: 12127
ENVIRONMENT
is defined in index.php
that is pipeline
of each CI application file, you can access anywhere e.g model, view, controller, library
echo ENVIRONMENT;
Upvotes: 13
Reputation: 1769
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 for you. However, this will set the ENVIRONMENT based on where the application is running, automatically.
Upvotes: 4