• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working with Configuration Files

#1
The quote below is from the CI v4 documentation. Specifically, from the last paragraph of the Handling Different Environments section.

I want to know if the line I put in bold is accurate. I don't see anything in the source code that would make the statement true.

Quote:When your application runs, this file will be automatically loaded and the variables will be put into the environment. This will work in any environment except for production, where the variables should...

Perhaps the sentence relates to a past, possibly abandoned goal and the docs have not caught up?
Or is it a reference to a yet-to-be-implemented behavior?

(Also possible: I completely misunderstand what's being said.)
Reply

#2
Thank you for pointing that out. I just pushed up a change for that page. But basically - the .env file is loaded in all environments.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply

#3
A follow-up question.

So, if I understand correctly, given the very typical development + production environments setup, each would need their own .env file. That feels a bit fragile to me because it would be far too easy to accidentally overwrite the production version with the dev version during an FTP upload for instance. (Something I used to do on a regular basis with config.php before I figured out how to properly handle multiple environments under v3.  Blush )

Is there any way to leverage the /Config/Boot environment specific files to manage values as set in the Config\App, Config\Database, etc. namespaces?
Reply

#4
The Config/Boot options happen early enough it's possible that you could do that, though I've never tried something like that honestly. If you're concerned about it being fragile, you can always use other ways to set environment variables on your server, like through bash profiles, etc, and not use the .env file itself. Though, personally, I'd find ways to avoid using FTP for deployment, if possible.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply

#5
(05-29-2018, 07:06 AM)dave friend Wrote: A follow-up question.

So, if I understand correctly, given the very typical development + production environments setup, each would need their own .env file. That feels a bit fragile to me because it would be far too easy to accidentally overwrite the production version with the dev version during an FTP upload for instance. (Something I used to do on a regular basis with config.php before I figured out how to properly handle multiple environments under v3.  Blush )

Is there any way to leverage the /Config/Boot environment specific files to manage values as set in the Config\App, Config\Database, etc. namespaces?

I'm not sure if I understand you correctly, - but I may mention an implementation which covers my needs very well. I've an app which I deploy on multiple sites, - which has different configurations. I've customized the index.php. Based on a logic where I look for a folder under config which has a name equal the current hostname using the gethostname() function. If the "hostname" folder exist, - all configuration files are read from this folder. If the folder doesn't exist, - default config files are read from /config. I feel this is a very flexible solution.


Attached Files Thumbnail(s)
   
Reply

#6
I downloaded CI4 to check out how it might handle a multi-environment and multi-domain setup.  I haven't used CI since CI2 so felt a bit out of touch, but suspected CI4 would be a winner.  I scoured this forum and the wider web for tips on how to set this up.  Unfortunately, the tips around CI3.x are not particularly helpful if you're relatively new to recent versions of CI... and the tips for CI4 on this particular aspect of configuration are incomplete.  This is not criticism.  I'm a long-standing member of the open-source community, so just sharing my experience, which is fairly typical of major new framework release.  I got there in the end, so I thought I would add a little more insight so that anyone else grappling with this setup might find it a little easier than I did.

Using .env turned out to too fiddly, given differences between our particular dev and live environments (win v unix).  It just wasn't versatile enough.  However, much depends on the nuances of what you're trying to achieve and how much or how little interoperability is required between the various domains/modules.  In our case the interoperability requirements are high.  I found that the combination of Apache directiing all requests to pubic/index.php, the customisation of public/index.php and the introduction of a new Domain class to handle initial routing to dedicated application folders, with fallback to a default application setup - all before loading system/bootstrap.php - proved to be the most efficient and manageable solution. 

Overall impressions of CI4 and this community so far: Wow! Really good! Hats off to you guys.
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.