Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you add abstract class library in the Codeigniter framework?

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 () {};

}

When I try to load the AbstractClass from controllers as follows:

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

I get Unable to load the requested class: AbstractClass error.

What am I doing wrong? Should I just include the file rather than loading it?

Thanks

like image 277
Cory Avatar asked Feb 23 '11 22:02

Cory


1 Answers

Well obviously you cannot load an abstract class directly as this goes against the point of an abstract class.

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.

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.

like image 83
Phil Sturgeon Avatar answered Sep 27 '22 17:09

Phil Sturgeon