env file and boolean values such as true or false |
Inside the .env file, how should I deal with boolean variables?
In the original file, for example, I find variables set to true and one set to 'true'. Code: honeypot.hidden = 'true' I've set my variable to both true and 'true', but it's always treated as a string. I'm using getenv() to retrieve the value, is there maybe some other function that returns a boolean instead of a string in these cases?
getenv() returns string or false.
https://www.php.net/manual/ja/function.getenv.php You can get the value as bool if you use Config class. See https://codeigniter4.github.io/CodeIgnit...-variables
(11-21-2022, 02:54 AM)kenjis Wrote: getenv() returns string or false. I think there was some helper that could handle this, unfortunately it's not a variable to configure a class, so either I use 0/1 or I have to do a string comparison, thanks kenjis
You can use env() in CI4.
Try it.
(11-21-2022, 03:12 AM)kenjis Wrote: You can use env() in CI4. I tried it and it works, where can I find it in the documentation? EDIT: okay, found it https://codeigniter.com/user_guide/gener...ht=env#env it would be better to mention it in the configuration section too in my opinion Thanks again kenjis
I think the solution is to let the Dotenv value to empty.
Let's say I have a boolean Dotenv variable such as email.DSN. To set it to false, I use: Code: # Use the following to set the value to false If I set any other value, it will be considered as true, event if I set it to false. For example the following values will result in true in the code. Code: # All the following values will be considered true Note: I don't think using env() function is a good solution if the Dotenv variable corresponds to a config value. In my example, there is a 'DSN' variable in the app/Config/Email.php file: PHP Code: public bool $DSN = false; |
Welcome Guest, Not a member yet? Register Sign In |