我正在使用Codeigniter 3x,我想在我的Codeigniter项目中创建CMS的某些部分,比如从CSS/JS/ header_view.php
,footer_view.php
读取/加载内容文件并保存它以便覆盖该文件,如wordpress编辑做。
我该怎么做?
答案 0 :(得分:0)
这里的步骤:
要显示文件列表,请使用:
$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)
始终确保重新创建文件的完整路径。