Welcome Guest, Not a member yet? Register   Sign In
Use of Helper and libraries
#1

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.
Reply
#2

Helpers are method/functions where Libraries are classes with methods/functions
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
Reply
#4

(This post was last modified: 10-04-2017, 02:46 AM by ktmonty.)

(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.
Reply
#5

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.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#6

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




Theme © iAndrew 2016 - Forum software by © MyBB