【发布时间】:2016-10-22 09:45:44
【问题描述】:
我正在使用 Codeigniter 3x,我想在我的 Codeigniter 项目中创建 CMS 的某些部分,例如从 CSS/JS/ header_view.php、footer_view.php 读取/加载内容文件并将其保存,以便它像 wordpress 编辑器一样覆盖该文件。
我该怎么做?
【问题讨论】:
标签: php codeigniter
我正在使用 Codeigniter 3x,我想在我的 Codeigniter 项目中创建 CMS 的某些部分,例如从 CSS/JS/ header_view.php、footer_view.php 读取/加载内容文件并将其保存,以便它像 wordpress 编辑器一样覆盖该文件。
我该怎么做?
【问题讨论】:
标签: php codeigniter
步骤如下:
要显示文件列表,只需使用:
$dir = 'path/to/your/css/files'
$files = glob($dir.'*');
现在在您看来,只需为每个文件创建一个指向您的控制器方法的链接,该方法接受文件名,例如:
foreach($files as $file){
<li><a href="path/to/your/controller/method/".$file>$file</a></li>
}
通过这种方式,您可以获得文件的链接,因此您可以重新创建您应该知道的完整路径(如果您愿意,您可以使用一些 data- 属性扩展链接以使其更容易)。
现在你在控制器方法中,所以只需加载文件内容并将其发送到视图:
$file_name = ''; // the one you get from the method link
$content = read_file($file_name);
// load the view and the editor
现在允许用户进行他/她想要的所有更改,然后保存数据:
$file_name = ""; // Name of the file, you can get it from the url, or adding as input in the form
$file_content = html_entity_decode($this->input->post('file_content'));
write_file($file_name , $file_content)
始终确保重新创建文件的完整路径。
【讨论】:
$dir = 'path/to/your/css/files'; 我需要在这里使用 base_url 吗?