How to create custom helper in codeigniter?

Today we will learn how to create custom helper in codeigniter.  Codeigniter is very powerful as well as very fast php MVC framework. We can create any type of web application with codeigniter. Codeigniter provide us number of defined libraries and helpers so that we can achieve our goal. But sometime we need some custom things so that we can full fill our conditions. codeigniter give us provision to create custom library or custom helper so that we can achieve our goal.

Now we will learn that how we can create custom helper in codeigniter. I will show you practical code for this. Suppose, we need some function that print the debug information of code. For example, I want to show array information in specific format. I will write the following code for this:

When you see the preview of this code it will look like the following:

This is small array, what happened if my array will contain huge elements. I have created one solution for this and that solution will provide the following result:

I have created this solution as helper in codeigniter. If you don’t know anything about codeigniter helper then read from this link.

  • Create the following file with name custom_debug_helper.php in application/helpers folder.

  • Load this helper in your controller like following:

  • Use this helper in your view for debugging, like the following

Remember on thing that don’t create your custom helper in system folder because it is core functionality folder of codeigniter.

I hope this article help you. If you find this article helpful then share this as much as you can so that this article become helpful for other user and they can solve their problems.