欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

TP5(thinkPHP框架)實(shí)現(xiàn)后臺(tái)清除緩存功能示例

 更新時(shí)間:2019年05月29日 11:38:49   作者:qq_37138818  
這篇文章主要介紹了TP5(thinkPHP框架)實(shí)現(xiàn)后臺(tái)清除緩存功能,結(jié)合實(shí)例形式分析了thinkPHP5結(jié)合layui插件實(shí)現(xiàn)后臺(tái)緩存清除相關(guān)的文件遍歷、刪除等操作技巧,需要的朋友可以參考下

本文實(shí)例講述了TP5(thinkPHP框架)實(shí)現(xiàn)后臺(tái)清除緩存功能。分享給大家供大家參考,具體如下:

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

1--common的文件

/**
 * 循環(huán)刪除目錄和文件
 * @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');
    //詢問(wèn)框
    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

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門(mén)教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門(mén)教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門(mén)教程》及《PHP模板技術(shù)總結(jié)》。

希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論