class Caching extends CI_Controller {
public function index()
{
$this->load->view('employee/index');
$this->output->cache(15);
}
}
我可以在cache文件夹中为index.php创建缓存,但我想在cache / employee / cache文件下创建一个文件夹
根据视图调用的文件夹动态创建文件夹
答案 0 :(得分:1)
您需要在application/config.php
/*
|--------------------------------------------------------------------------
| Cache Directory Path
|--------------------------------------------------------------------------
|
| Leave this BLANK unless you would like to set something other than the default
| system/cache/ folder. Use a full server path with trailing slash.
|
*/
$config['cache_path'] = 'var/www/site/public_html/application/cache/employee/cachefile';
// ^ or whatever your server path to that folder is! ^
答案 1 :(得分:1)
我想你想在缓存文件夹中创建子文件夹。因此,您可以修改system / helpers / file_helper.php
函数write_file()应该是这样的
function write_file($path, $data, $mode = FOPEN_WRITE_CREATE_DESTRUCTIVE)
{
// Modifications here
# Usage:
# $this->cache->save('user/favourites/page1', $favourites);
# Will create folder 'user/favourites' at cache folder and file 'page1' with data
if (strpos($path, '/') !== false) {
$folders = explode('/', $path);
unset($folders[count($folders) - 1]);
$dir = implode('/', $folders);
mkdir($dir, 0744, TRUE);
}
// End of modifications
if ( ! $fp = @fopen($path, $mode))
{
return FALSE;
}
flock($fp, LOCK_EX);
fwrite($fp, $data);
flock($fp, LOCK_UN);
fclose($fp);
return TRUE;
}
或者您可以创建文件my_file_helper.php以“扩展”系统帮助程序并覆盖此功能。这是更好的解决方案。