Articles → PHP CODEIGNITER → Override existing helper in codeigniter

Override existing helper in codeigniter












File naming convention









Example - Add a new function in the existing helper




$this->load->helper('date');

$bad_date = '199605';

$better_date = nice_date($bad_date, 'Y-m-d');

echo $better_date;




Picture showing the output of nice_date function

Click to Enlarge



<?php
function showmessage()
{
    echo "Calling showmessage";
}




$this->load->helper('date');

showmessage();




Picture showing the output of the function showmessage added in date helper

Click to Enlarge


Example - Override the existing function with new functionality




function nice_date($date, $format)
{
echo "nothing";
}




$this->load->helper('date');

$bad_date = '199605';

nice_date($bad_date, 'Y-m-d');




Picture showing the output when nice_date function is overridden

Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Thursday, July 23, 2020

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250