CodeIgniter: Decision making for creating of library & helper in CodeIgniter

First of all, you should be sure that you understand the difference between CI library and helper class. Helper class is anything that helps any pre-made thing such as array, string, uri, etc; they are there and PHP already provides functions for them but you still create a helper to add more functionality to them.

On the other hand, library can be anything like something you are creating for the first time, any solution which might not be necessarily already out there.

Once you understand this difference fully, taking decision must not be that difficult.


Well the choice comes down to set of functions or class. The choice is almost the same as a instance class verses a static class.

If you have just a simply group of functions then you only need to make a group of functions. If these group of functions share a lot of data, then you need to make a class that has an instance to store this data in between the method (class function) calls.

Do you have many public or private properties to store relating to your notification messages?

If you use a class, you could set multiple messages through the system then get_messages() could return a private array of messages. That would make it perfect for being a library.


There is a question I ask myself when deciding this that I think will help you as well. The question is: Am I providing a feature to my framework or am I consolidating?

If you have a feature that you are adding to your framework, then you'll want to create a library for that. Form validation, for example, is a feature that you are adding to a framework. Even though you can do form validation without this library, you're creating a standard system for validation which is a feature.

However, there is also a form helper which helps you create the HTML of forms. The big difference from the form validation library is that the form helper isn't creating a new feature, its just a set of related functions that help you write the HTML of forms properly.

Hopefully this differentiation will help you as it has me.