开发者

codeigniter - best practice library with many classes

开发者 https://www.devze.com 2023-02-09 19:52 出处:网络
I\'m building a library for our CodeIgniter app, but it requires many classes (currently I\'m at 12).

I'm building a library for our CodeIgniter app, but it requires many classes (currently I'm at 12).

Is there a best practice for packaging these many clients into one library. So I can just make one call to load it. i开发者_如何转开发.e:

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

Thanks!


As Summer points out, they have handled this situation somewhat elegantly in CI 2.0 with the concept of Drivers.

With a Driver, you actually create a subdirectory within your 'libraries' directory that contains your 'super' class, and another directory for 'child' classes. Better visual representation of the structure...

codeigniter - best practice library with many classes

This was taken from Here.

and once you have constructed your library, here is the documentation on how to use it.


In CI 2.0, there are drivers to handle this situation. Good luck!


In CodeIgniter 3.1.9 when you load a library file, all classes in this file are included into code.

Let's say in soaplibrary.php you have

class SoapLibrary {
   public function someMethod(...

class Test {
   public function anotherMethod(...

In your controller you can do:

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

//now on you can do
$this->soaplibrary->someMethod();

//but also
$test = new Test();
$test->anotherMethod();

CodeIgniter attempts to call the constructor of class SoapLibrary, hence a class with that name must be in there.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号