set a variable in dashboard and get it in php

Permalink
I am using Concrete5 Cache API to speed up my single page, and now i set cache timeout to be 10 minutes in my php, it is hardcoded.

What i want to do now is create a variable which tells how long should the cache exist in dashboard, and get it in php code, so that i can config the cache timeout in dashboard dynamically.

I saw the develop documentation about Attributes, but the documentation is really hard to understand and don't tell anything useful, so i have to ask here, is anybody know how?

Any help will be thankful.

 
ronyDdeveloper replied on at Permalink Reply
ronyDdeveloper
You can create a dashboard single page to save the value in database.
it should have a textbox named "cache_time".

And in controller the code will be like
public function view(){
$pkg = Package::getByHandle('theme_handle');
if($this->post()){
  $pkg->saveConfig('CACHE_TIMEOUT', $this->post('cache_time'));   
  $this->set('message', t('Settings saved successfully.'));
}
}


Then in frontend you can access the code through
$pkg = Package::getByHandle('theme_handle'); 
$cache_time = $pkg->config('CACHE_TIMEOUT');


The $cache_time will store the value you saved in dashboard.

Note: You need to replace the "theme_handle" with your themes handle. And change it when you change any theme accordingly.

Rony
YuC replied on at Permalink Reply
found an easier way now:

create a page attribute with type number, and set it's value in single page.

in single page controller php file:

$c->getCollectionAttributeValue('attr_handle');

that's it!

Thanks anyway.
A3020 replied on at Permalink Reply
A3020
You can also use $c->getAttribute() which is shorter and does the same thing.