PHP头条
热点:

TP5(thinkPHP框架)实现后台清除缓存功能示例,tp5thinkphp


本文实例讲述了TP5(thinkPHP框架)实现后台清除缓存功能。分享给大家供大家参考,具体如下:

layui插件 http://www.layui.com/

1--common的文件

/**
 * 循环删除目录和文件
 * @param string $dir_name
 * @return bool
 */
function delete_dir_file($dir_name) {
  $result = false;
  if(is_dir($dir_name)){
    if ($handle = opendir($dir_name)) {
      while (false !== ($item = readdir($handle))) {
        if ($item != '.' && $item != '..') {
          if (is_dir($dir_name . DS . $item)) {
            delete_dir_file($dir_name . DS . $item);
          } else {
            unlink($dir_name . DS . $item);
          }
        }
      }
      closedir($handle);
      if (rmdir($dir_name)) {
        $result = true;
      }
    }
  }
  return $result;
}

2-控制器里的

/**
* 清除缓存
*/
public function clear() {
    if (delete_dir_file(CACHE_PATH) || delete_dir_file(TEMP_PATH)) {
      $this->success('清除缓存成功');
    } else {
      $this->error('清除缓存失败');
    }
}

3-html代码

<a href="javascript::void(0)" rel="external nofollow" onclick="clearPhp(this)" data-GetUrl="{:url('login/clear')}">清楚缓存</a>

4---js 代码

<script>
  function clearPhp(obj) {
    var url=obj.getAttribute('data-GetUrl');
    //询问框
    layer.confirm('您确定要清除吗?', {
          btn: ['确定','取消'] //按钮
        },
        function(){
          $.get(url,function(info){
            if(info.code === 1){
              setTimeout(function () {location.href = info.url;}, 1000);
            }
            layer.msg(info.msg);
          });
        },
        function(){});
  }
</script>

更多的功能和插件  地址:https://www.kancloud.cn/he_he/thinkphp5

更多关于thinkPHP相关内容感兴趣的读者可查看本站专题:《ThinkPHP入门教程》、《thinkPHP模板操作技巧总结》、《ThinkPHP常用方法总结》、《codeigniter入门教程》、《CI(CodeIgniter)框架进阶教程》、《Zend FrameWork框架入门教程》及《PHP模板技术总结》。

希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。

www.phpzy.comtrue/php/24831.htmlTechArticleTP5(thinkPHP框架)实现后台清除缓存功能示例,tp5thinkphp 本文实例讲述了TP5(thinkPHP框架)实现后台清除缓存功能。分享给大家供大家参考,具体如下: layui插件http://www.layui.com/ 1--common的文件...

相关文章

PHP之友评论

今天推荐