Welcome Guest, Not a member yet? Register   Sign In
How change Config (base_url) on a Controller

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'] = 'https://en.test.com';

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

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

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

@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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )

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. abc.mydomain.com - 1
2. xyz.mydomain.com - 1
3. other.mydomain.com - 0

Include to header file:

//check valid domain, $currentDomain = $_SERVER['SERVER_NAME'];
// use where clause in DB BUILDER, ex: where("domain LIKE '%mydomain.com'"); 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)

Theme © iAndrew 2016 - Forum software by © MyBB