如何在Codeigniter框架中添加抽象类库? [英] How do you add abstract class library in the Codeigniter framework?
问题描述
我在文件中有 libraries
文件夹中的 AbstractClass.php
$ b
I have the following code in file called AbstractClass.php
in the libraries
folder
abstract class AbstractClass {
abstract protected doSomething ();
}
class ConcreteClass extends AbstractClass {
public function doSomething () {};
}
当我尝试加载 AbstractClass
来自 controllers
如下:
When I try to load the AbstractClass
from controllers
as follows:
$this->load->library('AbstractClass');
我得到无法加载请求的类:AbstractClass
错误。
我做错了什么?
感谢
推荐答案
p>很显然,你不能直接加载抽象类,因为这违背了抽象类。
Well obviously you cannot load an abstract class directly as this goes against the point of an abstract class.
您可以将抽象类与另一个库一起放在一个文件中,但这是一个有点无意义,违反了一类一文件标准CI所有良好的标准)。
You can put an abstract class in a file along with another library, but that is a bit pointless and goes against the "one class one file" standard that CI (and all good standards) suggest.
您可以在库文件中包含include()这个文件,或者设置一个__autoload()函数。 __autoload()的最佳位置是config.php的底部。
You can include this file with an include() in your library files, or set up an __autoload() function to do it for you. Best place for an __autoload() is the bottom of config.php.
这篇关于如何在Codeigniter框架中添加抽象类库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!