Codeigniter如何为css / js / php创建CMS编辑器,如wordpress编辑器

时间:2016-10-22 09:45:44

标签: php codeigniter

我正在使用Codeigniter 3x,我想在我的Codeigniter项目中创建CMS的某些部分,比如从CSS/JS/ header_view.phpfooter_view.php读取/加载内容文件并保存它以便覆盖该文件,如wordpress编辑做。

我该怎么做?

1 个答案:

答案 0 :(得分:0)

这里的步骤:

  1. 向用户显示文件列表
  2. 允许他们点击文件
  3. 加载该文件内容并将其打印在视图或WYSIWYG编辑器中
  4. 当他们保存时获取整个内容并覆盖旧内容。
  5. 要显示文件列表,请使用:

    $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)
    

    始终确保重新创建文件的完整路径。