K
K
Khurshed Abdujalil2017-05-17 12:06:29
Yii
Khurshed Abdujalil, 2017-05-17 12:06:29

How to cache fragments in a widget in Yii2?

in the widget I write like this:

if ($this->beginCache('top-search-block' . '-' . md5(implode('|', $filter['filter'])), ['duration' =>  15 * 60 ])) { 
.....
$this->endCache();
}

I get the error
Unknown Method - yii\base\UnknownMethodException
Calling unknown method: frontend\widgets\Search\SearchWidget::beginCache()
works fine in the controller and view, but does not want to in widgets, although this was possible in Yii1, how can I do it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Timofeev, 2017-05-17
@akhur

The error clearly states.
I translate: The called beginCache() method is missing in frontend\widgets\Search\SearchWidget
You have an instance of the frontend\widgets\Search\SearchWidget class in $this
And beginCache() is a method that should apparently be called here Yii::$app->cache

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question