Use of Helper and libraries |
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.
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 )
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 )
(09-01-2017, 03:16 AM)InsiteFX Wrote: A CodeIgniter helper is a set of related functions (Common functions) which you could Thanks buddy for details. |
Welcome Guest, Not a member yet? Register Sign In |