Google News
logo
CodeIgniter - Interview Questions
Helper vs Library in CodeIgniter?
Helpers : Helpers are just small functions that help you avoid repetitive code and produce standard results. Whereas libraries contain classes, can include different files, talk to database etc.
 
Library : Library is used in object oriented context (Controller, …), while a helper is more suitable to be used within the Views (non object oriented).

Helper, Plugin and Library :

Since all three methods achieve the same ends. The question then is when do you use what?
 
Fortunately, CI has also provided that distinction in their user guide which you can go read it yourself.
 
For me, these are my guidelines on when to use what :

1. Plugins : I put all 3rd party codes I’m using in my application as Plugins. I would, as best as I can, try to use classes rather than straight function calls.

2. Helpers : Any standalone straight functions calls, which are repetitive in nature, I classify them as Helpers. For example, sorting functions, my own calculation functions, etc

3. Libraries : I classify my own classes as ‘Libraries’. Normally, if I’m already writing a class in my application, it would then to be the core logic of the application, as such, I group them all in the Library folder.
Advertisement