Welcome Guest, Not a member yet? Register   Sign In
how to set/overwrite the config-item for "language" pre controller?
#1

[eluser]uprocka[/eluser]
Hello everybody,

I know this question might have been already discussed here but I could not find a satisfying solution yet... perhaps I am overlooking something?!

I want to extract the language from the URI e.g. from the subdomain or a uri-segment... that I have managed on my own ;-)
But now the problem is where/when to overwrite the default config language-setting:

I tried to do it via:

1a) a post_controller hook:
CI instance exists but to overwrite the default config language-setting it is too late.

1b) a post_controller_constructor
CI instance exists but to overwrite the default config language-setting it is too late
(I need the new language to be available in the controller constructor ).

1c) a pre_controller hook
CI instance doesn't exist, get_instance cannot be called
SEE also: http://ellislab.com/forums/viewthread/108639/

2) extending the Controller Class
CI get_instance exists but overwriting the default config language-setting is too late. I am not sure why?

3) extending the Language Class (MY_Language)
CI instance doesn't exist, get_instance cannot be called
SEE also: http://ellislab.com/forums/viewthread/70655/

what am I overlooking? What is the best solution to get this done?

Thank you in Advance

uprocka
#2

[eluser]TheFuzzy0ne[/eluser]
I don't understand why this won't work by overriding the controller class. Are you sure you've overridden it correctly?

If it were me, I'd probably add a little logic to the config file, which would check the subdomain, and set the config item accordingly. This is the earliest available opportunity to do this, since the default language is defined in the config file, so it makes sense to configure it as the file is loaded.
#3

[eluser]uprocka[/eluser]
Thanks for the push in the right direction!

See, I was so focused on doing it with hooks or the Cotroller Class that I forgot about the Config Class.

I extended the Config Class now and it works like a charme!!! Additionally the code even got shorter!

PS:
yes I think I extended the Controller right:

Code:
class MY_Controller extends Controller
{
   function MY_Controller()
   {
      parent::Controller();
      $this->config->set_item('language', 'spanish');
      
   }


but somehow this gets overridden by the default value again - I don't know when the default config gets loaded but obviously later. Perhaps a CI-Professional can explain that...?
#4

[eluser]TheFuzzy0ne[/eluser]
When CodeIgniter runs, it loads the classes in this order:

Benchmark library
Hooks library
Config library
URI library
Router library
Output library.
Input library
Language library
Controller

At this point, the language library has only just been instantiated. No file have been loaded.

When you set the config setting in your controller, you should then be able to load language files with no problem. I think the problem is somewhere in your code.
#5

[eluser]uprocka[/eluser]
Ok then the problem is somewhere else and
I will find out why it does not work right for me in the Controller.


Thanks again!




Theme © iAndrew 2016 - Forum software by © MyBB