php CodeIgniter:“无法加载请求的类”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8026508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:47:51  来源:igfitidea点击:

CodeIgniter: "Unable to load the requested class"

phpcodeigniterautoloader

提问by StackOverflowNewbie

On my WAMP box, I did the following:

在我的 WAMP 盒子上,我做了以下事情:

  1. Added a file called /application/libraries/Foo.php
  2. Foo.php is a class, and it's name is Foo
  3. In /application/config/autoload.php, I added $autoload['libraries'] = array('foo');
  1. 添加了一个名为 /application/libraries/Foo.php 的文件
  2. Foo.php 是一个类,它的名字是 Foo
  3. 在/application/config/autoload.php中,我添加了 $autoload['libraries'] = array('foo');

Everything works fine. When I upload to my LAMP box, I get the following error:

一切正常。当我上传到我的 LAMP 盒子时,我收到以下错误:

Unable to load the requested class: foo

Unable to load the requested class: foo

Permission of /application/libraries/Foo.php is 0755. Owner is the same as the rest of the CI files. Taking fooout from autoload makes the problem go away.

/application/libraries/Foo.php 的权限为 0755。所有者与其余 CI 文件相同。以foo从自动加载出来,使问题消失。

Any ideas what might be wrong?

任何想法可能有什么问题?

回答by evan

In Windows, capitalization in paths doesn't matter. In Linux it does.

在 Windows 中,路径中的大小写无关紧要。在 Linux 中确实如此。

When you autoload, use "Foo" not "foo".

自动加载时,请使用“Foo”而不是“foo”。

I believe that will do the trick.

我相信这会奏效。

I think it works when you take it out of autoloading because codeigniter is smart enough to figure out the capitalization in the path and classes are case independent in php.

我认为当您将其从自动加载中取出时它会起作用,因为 codeigniter 足够聪明,可以确定路径中的大小写,并且类在 php 中与大小写无关。

回答by Ian

I had a similar issue when deploying from OSx on my local to my Linux live site.

从本地 OSx 部署到 Linux 实时站点时,我遇到了类似的问题。

It ran fine on OSx, but on Linux I was getting:

它在 OSx 上运行良好,但在 Linux 上我得到了:

An Error Was Encountered

Unable to load the requested class: Ckeditor

The problem was that Linux paths are apparently case-sensitive so I had to rename my library files from "ckeditor.php" to "CKEditor.php".

问题是 Linux 路径显然区分大小写,所以我不得不将我的库文件从“ckeditor.php”重命名为“CKEditor.php”。

I also changed my load call to match the capitalization:

我还更改了加载调用以匹配大写:

$this->load->library('CKEditor');

回答by Janzell Jurilla

If you're using a linux server for your application then it is necessary to use lowercase file name and class name to avoid this issue.

如果您的应用程序使用 linux 服务器,则有必要使用小写的文件名和类名来避免此问题。

Ex.

前任。

Filename: csvsample.php

文件名:csvsample.php

class csvsample {

}