Answer the question
In order to leave comments, you need to log in
Yii2 -> flush cache?
Hello World
I'm trying to reset the cache from the controller when updating the model, but somehow unsuccessfully, what's wrong?
The code:
public function actionUpdate($id)
{
$model = $this->findModel($id);
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$model->image = UploadedFile::getInstance($model, 'image');
if( $model->image ){
$model->upload();
}
unset($model->image);
$model->gallery = UploadedFile::getInstances($model, 'gallery');
$model->uploadGallery();
Yii::$app->session->setFlash('success', "{$model->name} обновлен(а)");
Yii::$app->cache->delete($header1);
return $this->redirect(['view', 'id' => $model->id]);
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
Yii::$app->cache->delete($header1);
delete($header1);
- does not clean deleteValue($header1);
- does not clean offsetUnset($header1);
- does not clean -
hard flush()
reset is not an option, but at least it works<?php if($this->beginCache($header1, array('duration'=>60))) { ?>
/ / /
<?php $this->endCache(); } ?>
Answer the question
In order to leave comments, you need to log in
Judging by the code above, $header1 is not defined at all in the actionUpdate method.
$header1
- must contain the key with which you created the cache, it is clearly null for you, so what should it work with? You are instructing to remove something, but not specifying what.
you have before
It must be set $header1
, so why don't you set it in the action? If not set, then it is worth opening a php tutorial, and from the first chapter. Where are variables and data types.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question