Reputation: 26274
I'm trying to set this property, but it's failing.
Code (view):
if (Yii::$app->user->identity && Yii::$app->user->identity->admin):
\yii\filters\HttpCache::$cacheControlHeader = 'no-cache'; // prevent Fastly from caching admin links
Docs: http://www.yiiframework.com/doc-2.0/guide-caching-http.html#cache-control
Yii 2.0.7.
Upvotes: 0
Views: 1858
Reputation: 1153
That property isn't a static property.
To set the cache control header, you'll need to add that class as a controller filter and set to property there. Something like this should work (YMMV with respect to extending controllers/behavior definitions):
public function behaviors() {
return array(
array(
"class" => "yii\filters\HttpCache",
"cacheControlHeader" => Yii::$app->user->identity && Yii::$app->user->identity->admin ?
"no-cache" : "public, max-age=3600",
),
);
}
Upvotes: 1