CodeIgniter Forums
When do i have to use a Library or Helper? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: When do i have to use a Library or Helper? (/showthread.php?tid=62741)



When do i have to use a Library or Helper? - groovebird - 08-20-2015

Hi,

i want to build a price calculation. The calculation consists of 2 components: a product (smartphone) and a smartphone tariff. This 2 things will be needed to calculate the price. I'm not sure how to intgrate this in CI. Should this be a library or a helper and why or is there another solution?

There are some other modules which should be used multiple times on my webpage. Should such modules be libraries?


RE: When do i have to use a Library or Helper? - solidcodes - 08-20-2015

Create your own custom library.


RE: When do i have to use a Library or Helper? - solidcodes - 08-20-2015

Libraries are php classes
Modules are Classes related to database. CRUD etc...

In your case just create a custom made library for your calcultor.
And setup/configure your helper, these are just methods in helping you in your daily coding...
Also create your Models for database.

Good Luck.


RE: When do i have to use a Library or Helper? - kenjis - 08-20-2015

It seems price calculation is your business logic. So it should be in models, if CI's model is not limited with only database access.

Helpers in CI are global functions. You don't need to create them, unless you really want to use.