How to create a helper in codeIgniter

A CodeIgniter helper is a PHP file with multiple functions. It is not a class they are just normal functions which you can access through out the application by just loading the helper.

Create a file and put the following code into it.

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('get_date'))
{
    function get_date()
    {
        return date("Y-m-d");
    }   
}

Save this to application/helpers/ . We shall call it “new_helper.php”
This can be in your controller, model or view.

$this->load->helper();  
echo get_date();//This will show  current date like 2019-12-19
Blog Catagory : Codeigniter