codeigniter - best practice library with many classes

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...

This was taken from Here.

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

codeigniter - best practice library with many classes, 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  Query Builder Class; Transactions; Getting MetaData; Custom Function Calls; Database Events; Database Utilities; Modeling Data. Using CodeIgniter's Model; Using Entity Classes; Managing Databases. Database Manipulation with Database Forge; Database Migrations; Database Seeding; Library Reference. Caching Driver; CURLRequest Class; Email Class

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

codeigniter, CodeIgniter attempts to call the constructor of class SoapLibrary , hence a class with that name must be in there. Multiple Classes inside a library, Is it possible to create 3 libraries containing all of the classes, load i find it good practice to ensure each class has a __construct() function. Best Practices¶ Before accepting any data into your application, whether it be POST data from a form submission, COOKIE data, URI data, XML-RPC data, or even data from the SERVER array, you are encouraged to practice this three step approach:

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.

best practice for 3rd party library?, The library in question is a single file with multiple classes and some non-class functions. Where would the best place for this file to go? 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

Multiple Classes inside a library, Is it possible to create 3 libraries containing all of the classes, load i find it good practice to ensure each class has a __construct() function. The Database Class CodeIgniter comes with a full-featured and very fast abstracted database class that supports both traditional structures and Active Record patterns. The database functions offer clear, simple syntax.

Multiple classes in same library, I've uploaded the 3 main files to: application/libraries/ but when I call the authentication In the cloudfiles.php file there are multiple classes. Helpers, as the name suggests, help you with tasks. Each helper file is simply a collection of functions in a particular category. There are URL Helpers, that assist in creating links, there are Form Helpers that help you create form elements, Text Helpers perform various text formatting routines

Write a good library, Of course I choose CodeIgniter for this project because I think it's a very good and I want to write a good code and use many libraries. Codeigniter has a very good data manipulation library along with itself, which is ‘active record class’. Though it’s a very good support from Codeigniter, still developers interested to work specially, like some may want to prefer to work with ORM, it isn’t enough. For that, you may want to use third-party library, doctrine is my choice.

Comments
  • Is it simply a case of putting all the classes concerned into separate files, in a folder, then using $this->CI->load->library('myfolder/myclass') for every class?
  • Unfortunately I'm working on a site that's using ver 1.7. But should we upgrade then I can see that this is the ideal solution.