Articles → PHP CODEIGNITER → Override Existing Helper In Codeigniter
Override Existing Helper In Codeigniter
- Add a new function in the existing helper.
- Override the existing function with new functionality.
File Naming Convention
- Create a file in the "Helpers" folder.
- File naming convention should be "MY_helperclass_helper.php". For example if you want to override date helper then the file name should be "MY_date_helper.php".
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;
Click to Enlarge
<?php
function showmessage()
{
echo "Calling showmessage";
}
$this->load->helper('date');
showmessage();
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');
Click to Enlarge