Welcome Guest, Not a member yet? Register   Sign In
Variables question
#1

Hi to everybody! I need to change the 'defaultLocale' var from a controller, in codeigniter 3 I could do that simply with this line:

$this->config->set_item('language', $lang);

But in Codeigniter4 if try to do this:

config('Config\\App')->defaultLocale = $lang;

The value of the global config don't change...

How can i do this? With the function config() i'm accessing to the global config or to a new instance of config?

Thx!
Reply
#2

What do you want to do exactly?
You should not change the defaultLocale, because it is the system default locale.
See https://codeigniter4.github.io/CodeIgnit...on-classes
Reply
#3

This tutorial will give you an idea of how its done in CodeIgniter 4, and it works.

IncludeBeer - Creating a multilingual website with CodeIgniter 4 (part 1)
IncludeBeer - Creating a multilingual website with CodeIgniter 4 (part 2)
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#4

(03-18-2024, 08:05 PM)Huisache Wrote: Hi to everybody! I need to change the 'defaultLocale' var from a controller, in codeigniter 3 I could do that simply with this line:

$this->config->set_item('language', $lang);

But in Codeigniter4 if try to do this:

config('Config\\App')->defaultLocale = $lang;

The value of the global config don't change...

How can i do this? With the function config() i'm accessing to the global config or to a new instance of config?

Thx!

The best move would be to add the CodeIgniter Settings official package to your application (https://settings.codeigniter.com/), then you can easily change defaultLocale like this:

PHP Code:
service('settings')->set('App.defaultLocale ''fr'); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB