0
PHP에 대해 많이 알지 못합니다. 내 프로젝트에는 3 개의 파일이 있습니다.config.php의 문자열 값을 바꿉니다.
첫 번째는 system.php이며 구멍 응용 프로그램 논리를 유지합니다. 여기 해당 코드 :
<?php
class Config {
protected $data;
protected $informaton;
protected $default;
public function load($file) {
$this->data = require $file;
$this->informaton = require $file;
}
public function find($key, $default = null) {
$this->default = $default;
$segments = explode(".", $key);
$data = $this->data;
foreach ($segments as $segment) {
if (isset($data[$segment])) {
$data = $data[$segment];
} else {
$data = $this->default;
break;
}
}
return $data;
}
public function exists($key) {
return $this->find($key) !== $this->default;
}
// this is the function i am trying to make valide
public function replace($value) {
$arrayvalues = explode(".", $value);
$informaton = $this->informaton;
foreach ($arrayvalues as $arrayvalue) {
if (isset($informaton[$arrayvalue])) {
$informaton = $informaton[$arrayvalue];
}
}
return $arrayvalues;
}
}
?>
, 3 일이 config.php를하고, 구성을 원하는 분야
<?php
require "config/config_system.php";
$config = new Config;
$config-> load('config.php');
// this is way i want to change setting.
echo $config-> replace("db.host" , "replace value");
?>
2 일이 config_system.php 인 구성을 보유하고 해당 코드를 logic.here.
<?php
return [
"installation" => [
// this is the value I want to change via a function to true.
"create_db" => "false",
"create_table" => "false"
],
"db" => [
"host" => "localhost",
"user_name" => "root",
"password" => ""
]
];
?>
이제는 기능을 통해 일부 설정을 변경하고 싶습니다. 내가 어떻게 해? 답에 대한 config_system.php에
건초 감사합니다. 함수가 오류를 표시하고 있습니다. explode()는 최소한 2 개의 매개 변수가 필요합니다. – sohidulpaltan
실수로 인해 미안합니다. –