Sharing some config value between classes

This question has a specific and general part.

Specifically, I have a package where the package controller and a single page controller both need to know a given string value. I would rather not hard code the value in both classes and either just hard code it in the package controller or even better yet hard code it in the concrete5-cif file. I tried using \Concrete\Core\Package\Package::getConfig()->set('name', 'stringvalue') and then \Concrete\Core\Page\Controller\PageController::get(), but it didn't work. What is a good way to accomplish this?

In general, what is the best way to answer these questions myself? I tried but didn't make much progress. I typically find myself including a bunch of syslog(LOG_INFO, json_encode(get_class_methods($bla))); however, feel there has to be something better.


View Replies: View Best Answer
hutman replied on at Permalink Best Answer Reply
Here is what I have done

use \Concrete\Core\Package\Package;
$package = Package::getByHandle('package_handle');
$config = $package->getConfig();
$config->save('config_handle', 'value');
$config_value = $config->get('config_handle', null);
NotionCommotion replied on at Permalink Reply
Actually, after trying it, I don't get the expected results but an empty array. Do you know what I am doing wrong?
$package = Package::getByHandle('gb_manual');
        $config = $package->getConfig();
        $config->save('config_handle', 'value');
        $config_value = $config->get('config_handle', null);
        syslog(LOG_ERR, json_encode($config_value));    //outputs []
hutman replied on at Permalink Reply
Can you put your actual code here so we can see it? Based on what you posted you should be getting the string "value" back.
NotionCommotion replied on at Permalink Reply
Thank you, and sorry I missed your request. Full code below.

namespace Concrete\Package\GbManual;
defined('C5_EXECUTE') or die('Access Denied.');
use Concrete\Core\Package\Package;
use Concrete\Core\Asset\AssetList;
class Controller extends Package
    protected $pkgHandle = 'gb_manual';
    protected $appVersionRequired = '8.5.1';
    protected $pkgVersion = '0.0.1';
    public function getPackageDescription()
        return t('Adds the GB manual to your website.');
    public function getPackageName()
NotionCommotion replied on at Permalink Reply
Hi hutman,

While troubleshooting this approach, I found that this approach saves the data in the DB which isn't ideal if it is being used for a single hit to the server.

As an alternative, C5 uses Laravel's container per Then per we can do:
$this->app->instance('', 'testdb');
$db_name = $this->app->make('');

Initial testing is promising. Any concerns of this approach? Thanks