1
我創造了我的編輯自定義配置文件 它`工作的成功,除了文件目錄的模型編輯自定義配置文件在網上笨
這是我的模型
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);
}
}
and view
<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
什麼是我應該設置在型號爲我的配置文件路徑 請任何幫助,正確的路徑!
感謝您快速的解答它'工作順利:) –
它的工作如預期? –