本文介绍了如何使用codeigniter在缓存文件夹中创建子文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
class Caching extends CI_Controller {
public function index()
{
$this->load->view('employee/index');
$this->output->cache(15);
}
}
我能够在cache文件夹中为index.php创建缓存,但是我想在cache/employee/cache文件下创建一个文件夹
I am able to create cache for index.php in cache folder, but I want to create a folder under cache/employee/cache file
根据视图正在调用的文件夹动态创建文件夹
creating Folder Dynamically based on which folder the view is calling
推荐答案我想您想在缓存文件夹中创建子文件夹.因此,您可以修改system/helpers/file_helper.php
I suppose you want to create subfolders in cache folder. So, you can modify system/helpers/file_helper.php
函数write_file()应该像这样
Function write_file() should be like this
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来扩展"系统帮助程序并覆盖此功能.这是更好的解决方案.
Or you can create file my_file_helper.php to "extend" system helper and override this function. This is much better solution.
更多推荐
如何使用codeigniter在缓存文件夹中创建子文件夹?
发布评论