[eluser]Daem0nX[/eluser]
Used CI 1.7.2 for an old project, now using 2.0.2 for a new project. Having an issue when trying to load a cache helper (delete cache) depending on which Helper folder I place it in. Tried searching, guessing I'm missing something simple. Hope someone can point out the issue and explain why this is happening.
From the manual:
"Helpers are typically stored in your system/helpers, or application/helpers directory. CodeIgniter will look first in your application/helpers directory. If the directory does not exist or the specified helper is not located there CI will instead look in your global system/helpers folder."
If I copy cache_helper.php into /application/helpers/ CI returns "Unable to load the requested file: helpers/cache_helper.php".
However if I copy cache_helper.php into /system/helpers/ CI loads the helper.
Using:
$this->load->helper('cache');
If it helps figure this out...
Code:
//* @link http://www.in-the-attic.co.uk/2010/02/07/codeigniter-cache-helper/
if ( ! function_exists('delete_cache'))
{
function delete_cache(array $pages = null)
{
// get an instance of codeigniter
$CI =& get_instance();
// pretty obvious, get the cache page from the config file
$path = $CI->config->item('cache_path');
// if config value is empty then set cache path as the basepath plus cache/ else if it's not
// empty then set $cache_path as $path.
$cache_path = ($path == '') ? BASEPATH.'cache/' : $path;
// check the cache directory even exists
if ( ! is_dir($cache_path) OR ! is_really_writable($cache_path))
{
// if it doesn't then log the error and return false
log_message('error', "Cache directory could not be found: ".$cache_path);
return false;
}
// check to see if a variable has been passed into the function, if not then assume they
// want to delete the cache for the current page
if(!isset($pages['0']) || strlen($pages['0']) < 1)
{
$pages['0'] = $CI->config->item('base_url').
$CI->config->item('index_page').
$CI->uri->uri_string();
}
// loop over the pages requested
foreach($pages as $uri)
{
// calculate the MD5 hash of the full URL, this is what codeigniter uses to name the cache file
$cache_path_tmp = $cache_path.md5($uri);
// check to see if we can find the file
if ( ! @is_file($cache_path_tmp))
{
// if we can't find the file then great, less work for us!
log_message('debug', "Unable to find cache file: ".$cache_path_tmp);
} else {
// if we find the file then attempt to delete it
if( @unlink($cache_path_tmp))
{
// if we successfully deleted it then rejoice!
log_message('debug', "Cache file deleted: ".$cache_path_tmp);
} else {
// otherwise, cry... and return false to stop further processing as something is wrong
log_message('error', "Unable to delete cache file: ".$cache_path_tmp);
return false;
}
}
unset($cache_path_tmp);
}
// assume everything has gone fine and return true
return true;
}
}