第一步:先贴出官网的解决方法清除缓存
清除模版缓存 不删除cache目录
/
public function clear_sys_cache() {
Cache::clear();
$this->success( '清除成功', 'index/index' );
}
/*
清除模版缓存 不删除 temp目录
/
public function clear_temp_ahce() {
array_map( 'unlink', glob( TEMP_PATH.DS.'/*.php' ) );
$this->success( '清除成功', 'index/index' );
}
/**
清除日志缓存 不删出log目录
/
public function clear_log_chache() {
$path = glob( LOG_PATH.'/' );
foreach ($path as $item) {
array_map( 'unlink', glob( $item.DS.'.' ) );
rmdir( $item );
}
$this->success( '清除成功', 'index/index' );
}
结合自己的ajax
js页面
<script type="text/javascript">
function clear_cache()
{
var xhr =new XMLHttpRequest();
xhr.onreadystatechange =function(){
if(xhr.readyState==4)
{
alert(xhr.responseText);
// document.getElementById('id_check_stu').innerHTML=xhr.responseText;
}
}
/*获得输入学号/工号的信息*/
// var ming = document.getElementById('form-first-name').value;
/*thinkphp框架所以操作都是控制器和操作方法的结合*/
xhr.open('get','{:url('Common/clear_cache')}');
xhr.send(null);
}
</script>
html页面
<button style="margin-top:8px;" type="button" tooltip="添加图片" class="btn btn-sm btn-azure btn-addon" onClick="clear_cache()"> </i> 清除缓存
</button>
控制器
Public function clear_cache()
{
// echo "1";
// exit;
// dump(TEMP_PATH);
// dump(glob( TEMP_PATH.DS.'.php' ));
array_map( 'unlink', glob( TEMP_PATH.DS.'/*.php' ) );
Cache::clear();
echo "清除成功";
exit;
}