Need to Display a Package Variable

Permalink
I have a package set up where the admin can go to the dashboard and enter a code (string), and this is saved in the package. I have this part working, and verified that it works by printing it on a test page.

However, for what I'm trying to achieve, my current code doesn't work. Here is what I have now:

$consumer_key = Config::get('consumer_key');

HOWEVER... for the script to work properly, it must be look like this:

$consumer_key = "somestringoftextornumbershere";

The first code sample above references what the admin entered in the form. However, I need that properly assigned like the 2nd code sample.

How do I do that? I think I'm missing something.

PineCreativeLabs
 
A3020 replied on at Permalink Reply
A3020
I don't get it. Config::get returns a string by default. What do you get? (var_dump)
mesuva replied on at Permalink Reply
mesuva
I think you may need to explain a bit more here as to what you are doing, you should be able to just use the return value however you like.

But I will suggest though that maybe you're getting mixed up because you're not retrieving the config value associated with your package.

If you just call Config::get, you're just calling the static function of Config, which defaults to a 'global' set of config values. So if you are creating a package, it's better to associate the key/value pair with the package handle, in this case you need to instantiate the config class and work with a config object:

$co = new Config();
$pkg = Package::getByHandle('my_package_handle');
$co->setPackageObject($pkg);
// now my config object is specifically for my package and I can go:
$co->save('my_key', 'a value' );
// and
$thevalue = $co->get('my_key');


Double check the docs -http://www.concrete5.org/documentation/developers/system/config-pre...
(you probably know this stuff growthcurve, just including it for completeness!)
PineCreativeLabs replied on at Permalink Reply
PineCreativeLabs
My package works like this:

1. User enters a key (string) in the fields which is on a dashboard single page.

2. In the controller, I am using this to save the value:
public function consumer_key() {
   $pkg = Package::getByHandle('my_package');
$pkg->saveConfig('consumer_key', $this->post('consumer_key'));
        $this->set('message',t('Key has been saved.'));   
        $this->view();
}

3. This saved key needs to be saved to a file that I have located in the "libraries" folder of the package. It must look like this:
$consumer_key = "user-generated-string-here";


Hope that makes more sense.