-1

我正在使用一个函数在 PHP 中创建 zip 文件。然后我在另一个函数中调用该函数。

我不知道为什么会出现以下错误:

致命错误:在 ... 中调用未定义的函数 create_zip()

这些功能都是公共的,并且在类内部,所以我无法弄清楚。

这是文档,为简单起见,我删除了所有其他功能的内容:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Judging {

    public $return_data;

    public function __construct()
    {
        $this->EE =& get_instance();
    }

    public function pre_judging_items() {
    }

    public function pre_judging_submission_accept() {
    }

    public function pre_judging_submission_decline() {
    }

    public function round_one_items() {
    }

    public function round_one_submission_decline() {
    }

    public function round_two_items() {
    }

    public function submission_form() {
    }

    public function counts() {
    }

    public function judged_list_singles() {
    }

    public function create_zip($files = array(),$destination = '',$overwrite = false) {

        if(file_exists($destination) && !$overwrite) { return false; }

        $valid_files = array();

        if(is_array($files)) {
            foreach($files as $file) {
                if(file_exists($file)) {
                    $valid_files[] = $file;
                }
            }
        }

        if(count($valid_files)) {
            $zip = new ZipArchive();
            if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) {
                return false;
            }
            foreach($valid_files as $file) {
                $zip->addFile($file,$file);
            }

            $zip->close();

            return file_exists($destination);
        }
        else
        {
            return false;
        }
    }

    public function judged_zip_singles() {

        $sql = "
            SELECT *
            FROM (
              SELECT *, @rn:=IF(@prevCat=category_id, @rn + 1,1) rn, @prevCat:=category_id
              FROM (
                SELECT sub.entry_id, sum(jud.stage_2) AS score, sub.member_group, sub.category_id, dat.field_id_48 as path
                FROM exp_judging AS jud
                JOIN (SELECT @rn:=0, @prevCat:=0) T
                LEFT JOIN exp_submissions AS sub ON jud.rel_id = sub.id
                LEFT JOIN exp_channel_data AS dat ON dat.entry_id = sub.entry_id
                GROUP BY jud.rel_id
                ORDER BY sub.category_id, sum(jud.stage_2) DESC
              ) T
            ) T
            WHERE rn <= 35
        ";

        $query = $this->EE->db->query($sql);


        $items = array();
        foreach ($query->result_array() as $key => $row) {
            $path = substr($row['path'], 11);
            $items[] = $path;
        }

        $result = create_zip($items,'single-files.zip');

        print_r($result);

    }
}

谁能明白为什么我会收到这个错误?

4

3 回答 3

4

您需要使用$this来访问里面的成员函数judged_zip_singles()

$result = $this->create_zip($items,'single-files.zip');
于 2013-10-10T15:00:10.140 回答
2
$result = $this->create_zip($items,'single-files.zip');
于 2013-10-10T15:00:42.987 回答
1

改变

$result = create_zip($items,'single-files.zip');

$result = $this->create_zip($items,'single-files.zip');
于 2013-10-10T15:05:46.293 回答