Welcome Guest, Not a member yet? Register   Sign In
Dynamically changing supported languages
#15

(10-31-2021, 09:15 AM)chronic Wrote: I tried to play a bit with the code of the page you suggested, but I couldn't find a solution, maybe it's a bit too much for my abilities.

I didn't test it, but I think all you have to do is define a new library in your app that extends the core class:

PHP Code:
<?php
namespace App\Libraries;

use 
CodeIgniter\HTTP\IncomingRequest as BaseIncomingRequest;

class 
IncomingRequest extends BaseIncomingRequest
{
    public function __construct($config, ?URI $uri null$body 'php://input', ?UserAgent $userAgent null)
    {
        parent::__construct($config$uri$body$userAgent);
        // your code here
        $this->validLocales service('settings')->get('App.supportedLocales'); 
    }


Then add a request() service in app/Config/Services.php that will load your library. You can copy the one in System/Config/Services.php and add a "use" statement to use your library:
PHP Code:
use App\Libraries\IncomingRequest;

    /**
    * The Request class models an HTTP request.
    *
    * @return IncomingRequest
    */
    public static function request(?App $config nullbool $getShared true)
    {
        if ($getShared) {
            return static::getSharedInstance('request'$config);
        }

        $config $config ?? config('App');

        return new IncomingRequest(
            $config,
            AppServices::uri(),
            'php://input',
            new UserAgent()
        );
    

Like I said, I didn't test this code, but it should be close to what you need to do.
Reply


Messages In This Thread
RE: Dynamically changing supported languages - by includebeer - 10-31-2021, 12:51 PM



Theme © iAndrew 2016 - Forum software by © MyBB