It would be nice if you easily customize helpers the way you can with the classes. Right now, if you want to add a function or change the functionality of a helper function you have to copy the entire helper file to your application/helpers directory and make your changes there. When your change is small, this seems a little unnecessary to have to copy all the unrelated functions to your new file. If the helper files were all updated, wrapping each function in an if ( ! function_exists()) and the Loader class was updated to load both the original helper and then one the the application/helpers directory, then you could add new functions or custom versions of the existing functions without duplicating all the other code. See below.
The current method in the Loader class for helpers:
function helper($helpers = array())
{
if ( ! is_array($helpers))
{
$helpers = array($helpers);
}
foreach ($helpers as $helper)
{
$helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper');
if (isset($this->_ci_helpers[$helper]))
{
continue;
}
if (file_exists(APPPATH.'helpers/'.$helper.EXT))
{
include_once(APPPATH.'helpers/'.$helper.EXT);
}
else
{
if (file_exists(BASEPATH.'helpers/'.$helper.EXT))
{
include(BASEPATH.'helpers/'.$helper.EXT);
}
else
{
show_error('Unable to load the requested file: helpers/'.$helper.EXT);
}
}
$this->_ci_helpers[$helper] = TRUE;
}
log_message('debug', 'Helpers loaded: '.implode(', ', $helpers));
}
My proposed new helper load method:
function helper($helpers = array())
{
if ( ! is_array($helpers))
{
$helpers = array($helpers);
}
foreach ($helpers as $helper)
{
$helper = strtolower(str_replace(EXT, '', str_replace('_helper', '', $helper)).'_helper');
if (isset($this->_ci_helpers[$helper]))
{
continue;
}
if (file_exists(APPPATH.'helpers/'.$helper.EXT))
{
include_once(APPPATH.'helpers/'.$helper.EXT);
$this->_ci_helpers[$helper] = TRUE;
}
if (file_exists(BASEPATH.'helpers/'.$helper.EXT))
{
include(BASEPATH.'helpers/'.$helper.EXT);
$this->_ci_helpers[$helper] = TRUE;
}
if ( ! isset($this->_ci_helpers[$helper]))
{
show_error('Unable to load the requested file: helpers/'.$helper.EXT);
}
}
log_message('debug', 'Helpers loaded: '.implode(', ', $helpers));
}
Example of structure in helper files:
if ( ! function_exists('some_function'))
{
function some_function()
{
// some code
}
}
if ( ! function_exists('another_function'))
{
function another_function'()
{
// some code
}
}
