Apply for Zend Framework Certification Training


              How to Create Custom Healper in Codeigniter

In this blog section we are going to discuss about helper .we already have inbuilt helper
in codeiniter like 'url'  which is used to get base_url() like wise if we want to create our own helper
then let say we have certain group of codes which will be repeated in a programme.

so to avoid the repeatation of code we can create an healper and then you can call
dfined helper in controller or views directly

Step - 1  Create Custom Helper

In application/helpers folder create a new php file date_helper.php.

if (! defined('BASEPATH')) exit('No direct script access allowed');
if (! function_exists('check_date')) {
    function check_date(){
        // get main CodeIgniter object
        $ci = get_instance();
        // Write your logic as per requirement

Step - 2 How to load custom helper globally:

Open your application/config.php file and search for the helper array and add your custom helper name to the array.

 $autoload['helper'] = array('app');

Step - 3 How to use custom helper

After loading the helper with any of the above methods you can use the helper function in your controller and views.


< First Getting Started With CodeIgniter URL Routing >

Ask a question

  • Question:
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question

Back to Top