请问这个 TP5 框架的页面,只要我一调用函数就疯狂重新加载是怎么回事?

请问一下这个代码需要修改什么地方,现在我就在页面加载的时候通过 self::zip($test)调用了一下那个函数,但是只要一加这一句网页就疯狂重新加载,去掉就好了请问各位大哥该如何修改呢?

<?php

namespace app\admin\controller;

use think\Config;
use think\Exception;
use think\Session;
use think\Db;
use app\admin\model\Crud;

class Download extends Permissions
{
    function download()
    {
        if (request()->isPjax()) {
            $search = '';
            $tj = '';
            if (Session::has('search')) {
                if (isset($_POST['search'])) {
                    if (input('search') === '') {
                        Session::set('search', null);
                    }
                    $search = input('search');
                    Session::set('search', $search);
                    $sentence = "(filename like '%$search%')";
                } else {
                    $search = Session::get('search');
                    $sentence = "(filename like '%$search%')";
                }
            } else {
                if (input('search') !== '') {
                    $search = input('search');
                    Session::set('search', $search);
                    $sentence = "(filename like '%$search%')";
                }
            }
//            开始时间,结束时间
            if (input('start_time') != null && input('end_time') != null) {
//                两个时间都不为空
                $s = strtotime(input('start_time') . ' 00:00:00');
                $e = strtotime(input('end_time') . ' 23:59:59');
                $tj['create_time'][] = array('egt', $s);
                $tj['create_time'][] = array('elt', $e);
            } else if (input('start_time') != null || input('end_time') != null) {
//                只选了一个时间点
                $s = input('start_time') != null ? strtotime(input('start_time') . ' 00:00:00') : '';
                $e = input('end_time') != null ? strtotime(input('end_time') . ' 23:59:59') : '';
                $tj['create_time'] = input('start_time') == null ? array('elt', $e) : array('egt', $s);
            }
            $num = input('num') ? input('num') : 10;
            $this->assign('num', $num);
            //        将选择的参数传递至 HTML
            $this->assign(['start' => input('start_time'), 'end' => input('end_time')]);//选择的合同签订时间段
            $this->assign('status', input('status'));
            $this->assign('low', input('low'));
            $this->assign('high', input('high'));
            $this->assign('search', $search);
            if (!empty($sentence)) {
                $download = Db::name('attachment')->where($tj)->where($sentence)->where('use', 'download_paper')->order('id', 'asc')->paginate($num);
                $test = Db::name('attachment')->where($tj)->where($sentence)->where('use', 'download_paper')->field('filepath,filename')->select();
            } else {
                $download = Db::name('attachment')->where($tj)->where('use', 'download_paper')->order('id', 'asc')->paginate($num);
                $test = Db::name('attachment')->where($tj)->where('use', 'download_paper')->field('filepath,filename')->select();
            }
            $page = $download->render();
            $this->assign(['download' => $download, 'page' => $page]);
            $this->assign(['test' => json_encode($test)]);
            $hetong = self::zip($test);
            $this->assign('hetong', $hetong);
            return $this->fetch();
        } else {
            Session::delete('search');
            $url = '';
            $url .= '?page=' . (input('page') ? input('page') : '');
            $url .= '&num=' . (input('num') ? input('num') : '');
            $url .= '&start_time=' . (input('start_time') ? input('start_time') : '');
            $url .= '&end_time=' . (input('end_time') ? input('end_time') : '');
            $this->assign('url', $url);
            return $this->fetch('page');
        }
    }

    function zip($test)
    {
        $current = getcwd();
        if (count($test) > 0) {
            foreach ($test as $k => $v) {
                $files = $current . $v['filepath'];
                $zip = new \ZipArchive;
                $zipName = '\uploads\admin\admin_thumb\\' . time() . '.zip';
                if ($zip->open($current .$zipName, \ZipArchive::CREATE) === TRUE) {
                    $zip->addFile($files, $v['filename']);
                }
            }
            $zip->close();
            return $zipName;
        }
        else{
            return 0;
        }
    }
}
?>
阅读 203
评论 2019-11-20 提问
    2 个回答

    new \ZipArchive;放在foreach外面啊

    评论 赞赏 2019-11-20

      找到原因了。。。把pjax.js的默认超时时长延长就行了

      评论 赞赏 2019-11-20
        撰写回答

        登录后参与交流、获取后续更新提醒