CodeIgniter Forums
Use of Helper and libraries - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Choosing CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=8)
+--- Thread: Use of Helper and libraries (/showthread.php?tid=68811)



Use of Helper and libraries - ktmonty - 08-29-2017

Hi,
 
can any one explain difference between helpers and libraries? I know that helpers are the function and libraries are the class but what is best practice to you use them?

Thanks.


RE: Use of Helper and libraries - InsiteFX - 08-29-2017

Helpers are method/functions where Libraries are classes with methods/functions


RE: Use of Helper and libraries - sasbass - 08-31-2017

http://www.webdeveloper.com/forum/showthread.php?199467-Differences-between-PHP-Classes-and-Straight-Include-Functions


RE: Use of Helper and libraries - ktmonty - 08-31-2017

(08-29-2017, 10:03 AM)InsiteFX Wrote: Helpers are method/functions where Libraries are classes with methods/functions

Thanks for reply. I know basic diffrence but in which situation we use helper and in which situation we use  Libraries.


RE: Use of Helper and libraries - InsiteFX - 09-01-2017

A CodeIgniter helper is a set of related functions (Common functions) which you could
use them within Models, Views, Controllers,.. everywhere. Once you load (include) that file,
you can get access to the functions. But a Library is a class, which you need to make an
instance of the class (by $this->load->library()).

Helpers can be used in any place.

For example I created my own asset_help that allows be to use the
base_url() for resources like css js etc; I autoload the helper and
can use it in my views for setting my css and js paths to the files.

Functions do one thing and do it great, my_function();
Compared to libraries do multiple things with one load instance.
$this->library_name->function();

Easier typing and less memory depending on the size of the files.


RE: Use of Helper and libraries - ktmonty - 09-04-2017

(09-01-2017, 03:16 AM)InsiteFX Wrote: A CodeIgniter helper is a set of related functions (Common functions) which you could
use them within Models, Views, Controllers,.. everywhere. Once you load (include) that file,
you can get access to the functions. But a Library is a class, which you need to make an
instance of the class (by $this->load->library()).

Helpers can be used in any place.

For example I created my own asset_help that allows be to use the
base_url() for resources like css js etc; I autoload the helper and
can use it in my views for setting my css and js paths to the files.

Functions do one thing and do it great, my_function();
Compared to libraries do multiple things with one load instance.
$this->library_name->function();

Easier typing and less memory depending on the size of the files.

Thanks buddy for  details.