While updating a Fuel 1.3 application to 1.4, I encountered a problem retrieving language with Config class. I work in a multi-lingual environment, so the language in config is set to null.
Here is the way to reproduce the problem:
1. In my fuel/app/config/config.php file, I have:
'language' => NULL, // Default language
2. In fuel/app/classes/controller/welcome.php, I have:
The echo in the controller (point 2) successfully displays the language that has been set while the echo in the view (point 3) doesn't display anything.
This happens only with language, other configs seems to work fine.
This is caused by the fact that a request now stores and resets the language. Problem is that views are by default late-rendered, only after the request has been completed. At that time, the Config (which is global) no longer reflect the state of the config at the time of the request.
For clarification, here is the functional behaviour I'm expecting :
1. A main request is called and will define a language for the very first time (e.g.based on URL first segment, browser, session language settings);
2. The main request launches sub-requests that will by default use the language set up of the main request. Some of these sub-requests might switch to another language if they needed to.
The problem I see in the management of language in fuel/core/classes/request.php with the execute() method is that for this very first request, there is no language previously defined (the config language being set to null). So, at the end of the execute method, the language is set back to… null.
Someone suggested to me to set the language before this first request instead of inside it. This seems to be an interesting solution. I might do that in bootstrap.php. What do you think about that ? Should that be the good way to manage language when it is defined to null in the config file ?
Ideally you should set your default language in the config file, instead of using NULL. But that still causes problems if you want to switch language.
Problem is that language is a request context parameter, but when Views or Viewmodels are lazy rendered (and this is the default), the code in them will only be executed long after the request is finished, so that context is no longer available.