Skip to content

How to Extend CodeIgniter Helper?

Last updated on January 17, 2018

CodeIgniter Helper Function are available anywhere in the code, more than 20 CI Helpers are there(URL, Form, Directory, …etc). You can Easily Extend CodeIgniter Helpers. CodeIgniter Helper is just a PHP File with the bunch of functions, CI helper is not a class.

You can extend a CodeIgniter helper in a similar way to controllers and models. First, save a file called “MY_[name]_helper.php” to application/helpers where [name] is the name of the helper. To extend the URL helper it would be “MY_url_helper.php”. There is no need to extend any class here as helpers are just a bunch of functions. 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:


You load an extended helper the same way you load a normal helper. To load the url helper from a controller (which is the best practice) just use $this->load->helper(‘url’);. This makes your new functions available globally. Remember this means you access them directly (not with $this->url_helper->my_function()).

If you use this helper in a lot of locations you can have it load automatically by adding it to the autoload configuration file.

$autoload['helper'] = array('url');
0 0 votes
Article Rating
Subscribe
Notify of
guest

1 Comment
Most Voted
Newest Oldest
Inline Feedbacks
View all comments