Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
CakePHP:对成员函数的调用_Php_Cakephp - Fatal编程技术网

CakePHP:对成员函数的调用

CakePHP:对成员函数的调用,php,cakephp,Php,Cakephp,我在CakePHP中开发了一个帮助程序来上传文件,但是当我在操作中使用它时,它返回了一个错误。 我知道这个错误的意思,我试图用public$helpers=array('Session','File','Html')调用helper在控制器中,但发生相同的情况。我不知道该怎么办。 错误: FileHelper.php: $info['name'] = $File['name']; $info['tmp'] = $File['tmp_name'];

我在CakePHP中开发了一个帮助程序来上传文件,但是当我在操作中使用它时,它返回了一个错误。 我知道这个错误的意思,我试图用
public$helpers=array('Session','File','Html')调用helper在控制器中,但发生相同的情况。我不知道该怎么办。
错误:

FileHelper.php:
        $info['name'] = $File['name'];
        $info['tmp'] = $File['tmp_name'];
        $info['ext']['mime'] = $File['type'];
        $info['ext']['ext'] = $typeq[1];
        $info['size']['b'] = $File['size'];
        $info['size']['kb'] = $File['size'] / 1024;
        $info['size']['mb'] = $info['size']['kb'] / 1024;
        $info['error'] = $File['error'];
        $info['hashed_name'] = $nname;
        if($getHashed):
            return $info['hashed_name'];
        else:
            return $info;
        endif;
    }else{
        return "A file was not specified.";
    }
}

/**
 * Função responsável pelo upload dos arquivos
 * @author Gabriel Cavalho
 * @param $File file required - Deve prover todos os índices que o campo 'file' oferece, tmp_name, name, etc.
 * @param $Options array required - Deve ser um array contendo as opçoes do upload, como o caminho de upload (path), se o nome deve ser 'hashed'
 */ 
public function upload($File, $Options){
    if(isset($File) && isset($Options)){
        if($Options['hash']){
            $File = $this->info($File);
        }
        if(empty($Options['path'])){
            $Options['path'] = WWW_ROOT . 'files' . DS;
        }
        if($Options['hashname']){
            $File['name'] = $File['hashed_name'];
        }
        if($File['size']['mb'] > 5){
            $File['error'] = 5;
        }
        if($File['error'] == 0){
            /**
             * No caso de não haver erros nenhum, essa parte é entrada em ação. 
             */ 
            if(move_uploaded_file($File['tmp'], $Options['path'] . $File['name'])){
                return true;
            }else{
                return "An error has ocurred while uploading file.";
            }
        }else{
            switch ($File['error']) {
                case 1:
                    return "The file size exceeds the size provided by php.ini file";
                    break;
                case 2:
                    return "The file size exceeds the size provided by the form (MAX_FILE_SIZE)";
                    break;
                case 3:
                    return "The file wasn't fully uploaded";
                    break;
                case 4:
                    return "No file was uploaded";
                    break;
                case 5:
                    return "The file wasn't upload successfuly, the file size exceeds 5MB";
                    break;
                case 6:
                    return "Missing tmp folder";
                    break;
                case 7:
                    return "Failed in attempt to write file to disk";
                    break;
                default:
                    return "Failed to upload file";
                    break;
            }
        }
    }else{
        return "Please, provide valid \$File and \$Options";
    }
}
}
?>
显示错误的行是:

$this->request->data['MainSlider']['slide'] = $this->File->info($this->data['MainSlider']['slide_file'], true);

重要的一点是,您希望使用帮助程序作为组件。Helper只能在视图中使用,您可以随意修改并强制使用它,但必须将上载逻辑移动到行为中。处理上传不是视图层的责任

可从控制器访问

,例如文件上载:


控制器视图组件的帮助器。

对不起,您的实际问题是什么?帮助器是处理文件上载最错误的位置之一。。。这是模型层的任务。还有一些插件可以很好地处理文件上传和文件管理@戴维戴尔:我能做些什么来解决这个问题problem@GabrielOak将实际的错误消息添加到您的问题中如何。。。?作为开发人员,您应该知道“不工作”和不提供错误消息或调试数据是毫无意义的。但是,帮助程序完全不符合您的要求。@burzum
致命错误:调用非对象文件上的成员函数info():/Users/diakonosdigital/Drive Diakonos/Google Drive/eJersusalem/WWW/ejerusalem/branchs/app/Controller/DashboardController。php行:614
文件上载应在模型层处理,这意味着一种行为。不是一个组件。是的,我同意你的观点。你是对的。更好的地方是行为。因为它是数据处理逻辑,所以应该将它移到那里。组件仅用于支持控制器。
$this->request->data['MainSlider']['slide'] = $this->File->info($this->data['MainSlider']['slide_file'], true);