Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
I am working on a module where I have custom config files for clients. I am able to specify a group name for my config file and use it in my code. However, I believe there is an unintended bug when using a config group name using dotted array notation. I give you an example.
I have a config file for my contact block view and call it using
. I can access any of the config variables in it using
. I can even dump the whole config group by using
What I would like to do is give a group name using dotted array formation like this:
. This way I can load several view config files in at once and access them by their respective view names inside each block to avoid any naming collisions.
The problem here is when you give a config group name using dotted array notation, you cannot access access any of the config variables. In the case of above, calling
results in the null default value. You can still dump the config contents by calling
I looked into the core code and I see that Fuel creates a single array key
with each variable below it. So when you call the Config::get() method, Fuel looks for the array key
which doesn't exist and returns the default value. However, if you specify a group name without any dots, it works fine because there's only a single array index defined and the Config::get() method sees it and parses it as a single array key.
In the Lang class, you can specify group names using dotted array notation and it works just fine.
I am not sure if the Config class was intended to work the same way in regards to group names, but it does feel like a bug since you can flat out dump the contents using the dotted array notation.
Adding the dotted array notation to the group which would make the config class consistent with the the framework as most classes work like this, and it would also be more flexible to avoid naming collisions if you need to load multiple config files as in my case.
It's a quick fix though. In the config load method where the array element is defined, instead of giving it an key name with the full group string, you simply need to switch it to use
static::$items, $group, $config
. This will setup the multi-level array. Please note that this is for Fuel 22.214.171.124. I see that the config class was redone in Fuel 1.8.1, however I can confirm that the issue is still there in the latest build.
Don't think it is a bug as dotted-notation support was added to Lang at a later date.
I just think it was never implemented for Config as well, the API also grew apart over the years, for some reason the $reload and $overwrite are swapped in the argument order for load().
I don't see any immediate downsides, I've pushed the change.
Add a Comment
It looks like you're new here. If you want to get involved, click one of these buttons!
Apply for Membership
↳ Job Board
↳ Installation & Setup
↳ Tips and Tutorials
↳ Code share
In this Discussion