I am having some trouble working with cache values. My code is as follows:
1 $size=Yii::app()->cache->get('imagesize');
2 if ($size===false) {
3 echo("size value is NOT set<br />");
4 $model = Settings::model()->findByPk('DefaultImageSize');
5 $cache['imagesize'] = $model->value;
6 } else {
7 echo("size value IS set <br />");
8 echo($cache['imagesize']);
9 }
It errors on line 8 - "Object of class Settings could not be converted to string". So clearly the variable $size is set, but I am unable to echo that value. I am a noobie, so I must be missing something very simple. Can anyone see what I am not seeing?
Thanks so much, lenye. That resolves that issue. But now, when I want to use that value to concatenate it to another variable (or something), how do I do that? I run into the same issue.
I think I resolved my problem. The issue was not the retrieval of the cache values, it was that it was never set correctly in the first place. I replaced the "if ($value===false) {…" with "if (isset($value)) {…" and no everything works just fine.