0

Creating and Extending Helpers in CodeIgniter

Creating and Extending Helpers in CodeIgniter

Creating and Extending Helpers in CodeIgniter.
Helpers are the group of functions which can be used in the anywhere in our code. In codeIgniter you get a lot of helper which is familiar with email,form ,url and many more. When you want a set of code which is use in all controller then you can create a helper with a function and that function you can used any where in the working code.
Extending a CodeIgniter pre defined Helper

To Extend a helper first save a file called “MY_[name]_helper.php” to application/helpers where [name] is the name of the helper to be extended. To extend the form helper it would be “MY_form_helper.php”. Just open php tags and start writing your functions to this file. Remember not to add a closing php tag as it may cause trouble with headers. It’s as simple as:

To load the form helper from a controller (which is the best practice) just use $this->load->helper(‘form’);. This makes your new functions available globally. Remember this means you access them directly (not with $this->date_helper->my_function()).
Creating a CodeIgniter Helper

To create a new CodeIgniter helper copy/paste the following code into a file called [name]_helper.php in application/helpers where [name] is the name of the helper:

Sandeep Kumar

Sandeep kumar is a web developer and a professinal blogger. He works for latest technologies and write articles what he learn. In ICodeHub he share web languages tutorials and other programming tips and tricks. if you need some help or have some suggestion then mail him at sandeep92pal@gmail.com without any hesitation. He believes in learning and sharing.