我正在使用一个函数在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);
}
}
谁能明白为什么我会收到这个错误?
答案 0 :(得分:4)
您需要使用$this
来访问judged_zip_singles()
中的成员函数:
$result = $this->create_zip($items,'single-files.zip');
答案 1 :(得分:2)
$result = $this->create_zip($items,'single-files.zip');
答案 2 :(得分:1)
变化
$result = create_zip($items,'single-files.zip');
与
$result = $this->create_zip($items,'single-files.zip');