Blog Details

Helper Functions



                                

What is Helper Functions ?

  • Helpers, as the name suggests, help you with tasks.
  • Each helper file is simply a collection of functions in a particular category.
  • There are URL Helpers, that assist in creating links, there are Form Helpers that help you create form elementsText Helpers perform various text formatting routines, Cookie Helpers set and read cookiesFile Helpers help you deal with files, etc.
  • Unlike most other systems in CodeIgniter, Helpers are not written in an Object Oriented format.
  • They are simple, procedural functions.
  • Each helper function performs one specific task, with no dependence on other functions.
 

* Loading a Helper :-

  • Loading a helper file is quite simple using the following function:
 

Syntax:

  • $this->load->helper('name');
  • Where name is the file name of the helper, without the .php file extension or the "helper" part.
 

Example:

  • $this->load->helper('url');
  • to load the URL Helper file, which is named url_helper.php, you would do this:
 

* Loading Multiple Helpers :-

  • If you need to load more than one helper you can specify them in an array, like this:
  • $this->load->helper( array(
'helper1', 'helper2', 'helper3'           )                           );  

* Auto-loading Helpers :-

  • If you find that you need a particular helper globally throughout your application, you can tell CodeIgniter to auto-load it during system initialization.
  • This is done by opening the application/config/autoload.php file and adding the helper to the autoload array.
 

* Using a Helper :-

  • Once you've loaded the Helper File containing the function you intend to use, you'll call it the way you would a standard PHP function.
  •  to create a link using the anchor() function in one of your view files you would do this:
 

Example :

  • <?php echo anchor('blog/comments', 'Click Here');?>
  • Where "Click Here" is the name of the link, and "blog/comments" is the URI to the controller/function you wish to link to.
 


Categories

CodeIgnitor

Latest posts

13.05.14
Implementing CRUD Operations ¶

<ul> <li>Now comes the fun part. We would like t

13.05.14
View

<ol> <li><a href="http://www.yiiframework.com/do

13.05.14
Creating Model

<ol> <li><a href="http://www.yiiframework.com/do

Get Free Quote