I’m using codeigniter v3.1.10
and i have two projects with domain name abc.example.com
and xyz.example.com
. i know that in codeigniter according to the environment production or development we could add folders application/config/production
and application/config/development
in config folder with their respective files in them. An example found in SO : –multiple environments with codeigniter, gives us a provision to add development/production
folders inside application/config
folder.
But what i’m looking for is domain specific folders inside application/config folder
. Is there a way that i could put two folders like application/config/abc.example.com
and application/config/xyz.example.com
with config.php, database.php and constant.php
files in them.
Advertisement
Answer
as per your requirement, you want multiple subdomain configu.
e.g for subdomain abc.exmaple.com
want to load abc
config folder.
for subdomain xyz.exmaple.com
want to load xyz
config folder.
in your index.php
$env= 'development'; list($subdomain,$host) = explode('.', $_SERVER["SERVER_NAME"]); $allowed_subdomains = ['abc','xyz']; $env = in_array($subdomain,$allowed_sbudomains) ? $subdomain : $env; define('ENVIRONMENT',$env);
in switch..case
below as a case for your subdomain
switch (ENVIRONMENT) { ... ... case 'testing': case 'production': case $subdomain: .... }
now create a folder as per your subdomain under the config folder and do your required configuration there.