Welcome Guest, Not a member yet? Register   Sign In
Is it possible to move Config folder into root?
#1

I'm just wondering if its possible to move Config directory into the root from App folder. Because i'm planning to release updates for my ci app and when users replace app directory they have re-correct their specific config values for example baseURL.

I think Config directory by default should be in the root directory. what you guys think?
Reply
#2

Instruct your clients to use the .env file, it does what you want.
Reply
#3

But the problem is config options like supportedLocales, appTimezone are not available in the .env file. but only available in the App.php config file. but those kind of config options are more likey get changed my the clients.

Is there any possibility that I can move config dir into app root from app dir?
Reply
#4

(This post was last modified: 09-14-2020, 05:55 AM by John_Betong.)

I generate a "LOCALHOST" constant in index.php and used in Config.php and Database.php to modify variables. I also generate a JB_BASEURL which is used in Config.php. to set $base_url.

File: Index.php
PHP Code:
define('LOCALHOST''localhost'===$_SERVER['SERVER_NAME']);

# dynamic BaseUrl - https://forum.codeigniter.com/thread-74649.html  
  
if( TRUE || DEFINED('AUTOMATIC_URL_DETECTION') ) :
    
$url = (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) 
        && 
        (
'on' == $_SERVER['HTTPS']) 
        ? 
"https://" 
        
"http://") .$_SERVER['HTTP_HOST']
        ;
    
$url .= str_replace
    
(
      
basename($_SERVER['SCRIPT_NAME']), 
      
''
      
$_SERVER['SCRIPT_NAME']
    );
  endif;  
  
defined('JB_BASEURL') ?: define('JB_BASEURL'$url); # app/Paths.php, etc 
Reply
#5

(This post was last modified: 09-14-2020, 01:28 PM by T.O.M..)

(09-13-2020, 06:43 PM)MrWhite Wrote: But the problem is config options like supportedLocales, appTimezone are not available in the .env file. but only available in the App.php config file.

Wrong. In .env file you can set any config option from any config file https://codeigniter.com/user_guide/gener...-variables

You can see an example of .env file - here you can see that there are options from App.php, Database.php and other config files from app/Config.


(09-14-2020, 05:54 AM)John_Betong Wrote: I generate a "LOCALHOST" constant in index.php and used in Config.php and Database.php to modify variables. I also generate a JB_BASEURL which is used in Config.php. to set $base_url.

File: Index.php
PHP Code:
define('LOCALHOST''localhost'===$_SERVER['SERVER_NAME']);

# dynamic BaseUrl - https://forum.codeigniter.com/thread-74649.html  
  if( TRUE || DEFINED('AUTOMATIC_URL_DETECTION') ) :
    $url = (isset($_SERVER['HTTPS']) && !empty($_SERVER['HTTPS']) 
        && 
        ('on' == $_SERVER['HTTPS']) 
        "https://" 
        "http://") .$_SERVER['HTTP_HOST']
        ;
    $url .= str_replace
    
(
      basename($_SERVER['SCRIPT_NAME']), 
      ''
      $_SERVER['SCRIPT_NAME']
    );
  endif;  
  defined
('JB_BASEURL') ?: define('JB_BASEURL'$url); # app/Paths.php, etc 

You can get rid of all this by adding different .env files to different environments.

Besides you can use CI_ENVIRONMENT variable https://codeigniter.com/user_guide/gener...ments.html
Reply
#6

As long as the Config file is extending BaseConfig, you can practically leave that Config file unchanged and have all your local changes to the .env file. If there are missing settings in the .env file, you can add that. Although undocumented, please note that the .env file does not support setting up array values. Strings, numbers, booleans, and null are only allowed values in the .env file. So if you need to set up array values, you need to set those up in the Config file itself.
Reply
#7

@T.O.M.

Many thanks for the link, it is the first time I have read that .env values take priority over app/Config.php, etc. and I have been using CodeIgniter4 since the Alpha version!

Perhaps adding a mention in the manual every time .env is mentioned?

Unfortunately the .env file is limited to values being hard-coded strings and my defined constants, and variables, etc cannot be used.

Also I update from localhost to my server using RSYNC and need to have a different .env file online.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB