Saving nested arrays in the configuration file
This is an open discussion with 3 replies, filed under Extensions.
Search
I tried saving serialized arrays in the configuration file in my first tries for an extension as well. It felt like abusing config.php
and I ended up using the database. So maybe that’s the way to go…
I have tried all kinds of fixes by strip-slashing the data on the way back out etc, but with regex patterns that have slashes in them it is a bit of a nightmare!!
This is a pain, I agree, however the problem is the config.php
file must be valid PHP
otherwise Symphony will crash. The alternative is to use some other plain text format.
I tried saving serialized arrays in the configuration file in my first tries for an extension as well.
What about base64_encode(serialize($myArray))
? No slashes would get added. It’s just not human readable in any way.
Alistair - thanks for the suggestions but I have gone the route of using the DB to store the data, it’s simply easier.
Also, pulling the route data is a single “SELECT * FROM…” which is not going to add much overhead to each page render which was one of my original concerns.
Create an account or sign in to comment.
I’m trying to save a nested array in the config.php file as part of my extension. I am having no luck and I have tried serialising the data with both serialize() and json_encode() but I think the core is adding slashes to the data so they will not de-serialize correctly.
Line 68 of class.configuration.php: -
I have tried all kinds of fixes by strip-slashing the data on the way back out etc, but with regex patterns that have slashes in them it is a bit of a nightmare!!
I may be missing a function that can save a nested array in the config for me, but when I tried the setArray() method with the config object, the nested array just saved as the word “Array”.
Any help appreciated.