What is Helper
In CodeIgniter there are helpers which are there to help you with different tasks. Every helper file is a collection of functions aiming towards a particular role. Some of the helpers are 'file helpers' which help you to deal with the file, 'text helpers' to perform various text formatting routines, 'form helpers' to create form element, 'cookie helpers' set and read cookies, 'URL helpers' which assist in creating links, etc.
Helpers are not written in Object Oriented format, instead they are simple, procedural functions, independent of each other.
To use helper files, you need to load it. Once loaded it is globally available to your controller and views. They are located at two places in CodeIgniter. CodeIgniter will look first for a helper in application/helpers folder and if not found there then it will go to system/helpers folder.
Loading a Helper
A helper can be loaded in controller constructor which makes them globally available, or they can also be loaded in specific functions which need them.
It can be loaded with the following code:
Write your file name here at the place of file_name.
To load URL helper,
You can also auto-load a helper if your application needs that helper globally by adding the helper in application/config/autoload.php file.
Loading Multiple Helpers
To load multiple helpers, specify them in an array,
html Helper Example
We are going to show you an example of html helper by using it in a basic website page. Here, we'll auto-load our helper.
Go to autoload.php file via application/config/autoload.php
In the above file, name your helper, here it is html.
In application/controllers there is file Form.php
In application/views there is file header.php
The first line is coded in php tag.
The other half coding for file header.php is shown in below snapshot.
In application/views there is file content.php
Here also the heading is written in php tag instead of html.
Final output is just like a normal page as shown below with the URL localhost/helper/index.php/Form.
But when we will see its open source (by pressing ctrl+u), you will see the following coding which simply shows html code and not php code what we have written above.