Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Get config information inside the _config file


Go to End


2 Posts   1597 Views

Avatar
-lohe-

Community Member, 5 Posts

26 August 2016 at 11:19pm

Edited: 26/08/2016 11:29pm

Hei,

I wanted to handle config file values via Admin. Therefor I started to explore, if there is any way to actually use config values inside the plugin's _config.php file.

Here what I want (NOTE! using 3.4.1):
1. Change the values inside the Admin -> Settings -> NewTab

2. In plugin's _config.php file I tried to use several different ways to get config data:
* Config::inst() - print_r/var_dump gives all the values as array
* Config::inst() -> get($this -> class, "PropertyName") or $this -> config() -> get("PropertyName") - returns empty
* SiteConfig::current_site_config() or any other similar variations based on previous two - Internal Server Error

3. Reason I try this is that plugin replaces SS default action BUT it requires some data to be inserted, that MUST BE. If NOT inserted, it should stay as default ..

Used links:
* http://api.silverstripe.org/3.3/class-Config.html
* https://docs.silverstripe.org/en/3.0/topics/configuration/
* https://docs.silverstripe.org/en/3.4/developer_guides/configuration/configuration/
* https://docs.silverstripe.org/en/3.4/developer_guides/configuration/siteconfig/

Ideas anybody?

Avatar
-lohe-

Community Member, 5 Posts

1 September 2016 at 7:47pm

Hi,

Got an answer in stackoverflow. Very interesting actually. Here is the answer http://stackoverflow.com/a/39260528/1441598