ClearCache.php 823 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <?php
  2. namespace backend\forms;
  3. use Yii;
  4. use yii\base\Model;
  5. /**
  6. * Class ClearCache
  7. * @package backend\forms
  8. * @author jianyan74 <751393839@qq.com>
  9. */
  10. class ClearCache extends Model
  11. {
  12. /**
  13. * @var int
  14. */
  15. public $cache = 1;
  16. /**
  17. * @var bool
  18. */
  19. protected $status = true;
  20. public function rules()
  21. {
  22. return [
  23. [['cache'], 'integer'],
  24. ];
  25. }
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function attributeLabels()
  30. {
  31. return [
  32. 'cache' => '缓存记录',
  33. ];
  34. }
  35. public function save()
  36. {
  37. if ($this->cache == true) {
  38. $status = Yii::$app->cache->flush();
  39. !$status && $this->addError('cache', '缓存清理失败');
  40. }
  41. return $this->hasErrors() == false;
  42. }
  43. }
粤ICP备19079148号