在线编辑codeigniter中的自定义配置文件


Edit custom config file online in codeigniter

我创建了一个用于编辑自定义配置文件的模型除了文件目录外,它的工作是成功的

这是我的型号

class Settings_model extends CI_Model{
    // replace config items
    public function edit_line($word, $replace) {
      $base_url = $this->config->base_url();
        $reading = fopen('../application/config/config_custom.php', 'r');
        $writing = fopen('../application/config/myconf_tmp.php', 'w');
        $replaced = false;
        while (!feof($reading)) {
          $line = fgets($reading);
          if (stristr($line, $word)) {
            $line = "  '$word' => '$replace','n";
            $replaced = true;
          }
          fputs($writing, $line);
        }
        fclose($reading); fclose($writing);
        // might as well not overwrite the file if we didn't replace anything
        if ($replaced)
        {
          rename($writing, $reading);
        } else {
          unlink($writing);
        }
    }
}

和我的控制器

class Settings extends My_Controller {
    public function __construct() {
        parent::__construct();
    }
    public function index() {
        if($this->input->post()) {
          foreach($this->input->post() as $key => $value){
              $edit = $this->Settings_model->edit_line($key, $value);
              echo $edit;
          }
        }
        // Load View
        $data['main_content'] = 'settings/index';
        $this->load->view('layouts/main',$data);
    }
}

并查看

<form action="<?php echo base_url().'settings/index';?>" method="post">
      <?php foreach($this->global_data as $key => $val):?>
      <div class="form-group">
          <label><?=$key?></label>
          <input type="text" name="config_item['<?=$key?>']'" class="form-control" value="<?=$val?>" />
      </div>
      <?php endforeach; ?>
      <button class="btn btn-success" type="submit">حفظ</button>
</form>

当我张贴我的表格时,我收到这个错误信息

A PHP Error was encountered
Severity: Warning
Message: fopen(../application/config/config_custom.php): failed to open stream: No such file or directory
Filename: models/settings_model.php
Line Number: 7

我应该在模型中为我的配置文件路径设置正确的路径是什么请帮忙!

检查

fopen('../application/config/config_custom.php', 'r');

试着这样使用,

fopen(APPPATH.'/config/config_custom.php', 'r');