【问题标题】:Edit custom config file online in codeigniter在 codeigniter 中在线编辑自定义配置文件
【发布时间】:2015-12-03 16:19:00
【问题描述】:

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

这是我的模特

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

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

【问题讨论】:

    标签: php file codeigniter filepath


    【解决方案1】:

    了解这一点,

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

    尝试这样使用,

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-01-15
      • 2016-10-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-08-02
      相关资源
      最近更新 更多