如何使用codeigniter在缓存文件夹中创建子文件夹?

编程入门 行业动态 更新时间:2024-10-27 06:31:04
本文介绍了如何使用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在缓存文件夹中创建子文件夹?

本文发布于:2023-11-01 11:21:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549202.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:缓存   如何使用   文件夹   文件   夹中

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!