CodeIgniter Forums
How change Config (base_url) on a Controller - Printable Version

+- CodeIgniter Forums (
+-- Forum: CodeIgniter 4 (
+--- Forum: CodeIgniter 4 Support (
+--- Thread: How change Config (base_url) on a Controller (/showthread.php?tid=81878)

How change Config (base_url) on a Controller - lelolenda - 05-13-2022

I want build a website with subdomains, to a multi-language purpose, and that solution can help me.

Code eg.

public function initController(RequestInterface $request, ResponseInterface $response, LoggerInterface $logger)
        //HERE something like that (but that dont work, of course)
        $config['base_url'] = '';

        // Do Not Edit This Line
        parent::initController($request, $response, $logger);

        // Preload any models, libraries, etc, here.

        // E.g.: $this->session = \Config\Services::session();

RE: How change Config (base_url) on a Controller - InsiteFX - 05-14-2022

@includebeer, Has a very nice tutorial on how to do this multilingual website.

Creating a multilingual website with CodeIgniter 4

He also has another tutorial for creating a website.

RE: How change Config (base_url) on a Controller - pvt - 05-14-2022

You can store info in database then use code to detect valid domain.
In admin controller, create CRUD to manager domain list:

//DATABASE TABLE domainList:
[domain, isActive, ... ]
1. - 1
2. - 1
3. - 0

Include to header file:

//check valid domain, $currentDomain = $_SERVER['SERVER_NAME'];
// use where clause in DB BUILDER, ex: where("domain LIKE ''"); where("isActive", 1); 
if(!$currentDomain in DB TABLE)
die ("Invalid domain");
$base_url = get_base_url();
//if domain in db - $base_url = current domain, else $base_url = default_url (get from file config)