5.7 Config setPackageObject() undefined function
Permalink 1 user found helpful
Hi,
I am trying to create config/preference options for my package working in Concrete5.7 but I get the following error:
My code is:
I have tried copying and pasting from the documentation but it still does not work. I took a look inside the Concrete/src/Support/Facade/Config.php file referenced which does not have the option to set a package object and neither does Facade.php (same dir path)
Any ideas on how to set this up in 5.7?
I am trying to create config/preference options for my package working in Concrete5.7 but I get the following error:
Call to undefined method Concrete\Core\Support\Facade\Config::setPackageObject()
My code is:
// Configuration Settings $co = new Config(); $co->setPackageObject($pkg); $co->save('default_raffle_start_date', 'NOW()'); $co->save('default_raffle_end_date', 'DATE_ADD(NOW(), INTERVAL 7 DAY)');
I have tried copying and pasting from the documentation but it still does not work. I took a look inside the Concrete/src/Support/Facade/Config.php file referenced which does not have the option to set a package object and neither does Facade.php (same dir path)
Any ideas on how to set this up in 5.7?
And one more note to this.
This does NOT work:
But this DOES work:
This is because you cannot save values to config groups. Which means that all the configuration values need to have a group.
This does NOT work:
$pkg->getConfig()->save('config_key', 'config_value');
But this DOES work:
$pkg->getConfig()->save('group.config_key', 'config_value'); // For example: $pkg->getConfig()->save('system.is_great', true);
This is because you cannot save values to config groups. Which means that all the configuration values need to have a group.
Thanks for the assistance guys.
I ended up using:
To set config item for package:
To get config item:
I ended up using:
To set config item for package:
$pkg->getConfig()->save('raffles.start_date');
To get config item:
$pkg->getConfig()->get('raffle.start_date');
>>>
use `$pkg->getConfig()->save()` for database based config, and `$pkg->getFileConfig()->save()` for filesystem based config. This config is accessible outside of your package by using the package handle as a config namespace: `\Core::make('config/database')->get('my_package_handle::some.config.item')`.
A config item key can be represented by this regex: `^(?:(?P<Namespace>.+?)::)?(?P<Group>[^.]+).(?P<Item>.+)$`
http://regex101.com/r/tI1vM7/3