When I try to use define('LANG', $this->uri->rsegment(2)); in constants.php, I got this error:
Using $this when not in object context in constants.php.
I have no clue why. I’m quite new with codeIgniter and I want to define a constant that will take the language from the URI. I have already done something similar using REQUEST_URI, but with uri->segment; that will be much easier.
The way codeigniter is architectured, you cannot use
$thisin config.php, because all the framework resources are not loaded by the time constant.php is loaded.In order to do what you need to, you should do the following:
Create a new custom config file, say app_config.php (you can call it whatever you want)
Add this code to app_config file:
Place this file in config folder (same folder where config.php is)
In autoload.php, add this config file’s name to be autoloaded as:
Now you will be able to access the constant LANG across the application..