限时免费试用:欢迎注册 api.bigmodel.org ,快速体验大模型 API 接入服务。
当前位置:首页 >开发者 >网站框架 >后端框架 >ThinkPHP

tp5设置永久配置项

分类:ThinkPHP时间:2018-09-06浏览:3151
/**
 * 修改扩展配置文件
 * @param array  $arr  需要更新或添加的配置
 * @param string $file 配置文件名(不需要后辍)
 * @return bool
 */
function extraconfig($arr = [], $file = 'extraconfig')
{
    if (is_array($arr)) {
        $filename = $file . EXT;
 
        $filepath = APP_PATH . 'extra/' . $filename;
        if (!file_exists($filepath)) {
            $conf = " $value) {
            $conf[$key] = $value;
        }
 
        $time = date('Y/m/d H:i:s');
        $str = " $value) {
            $str .= "\t'$key' => '$value',";
            $str .= "\r\n";
        }
        $str .= '];';
 
        file_put_contents($filepath, $str);
        
        return true;
    } else {
        return false;
    }
}
$arr = [
    'name' => 'extracofig',
    'hello' => 'world'
];
app/extra/web.php
 'extracofig', 
    'hello' => 'world'
]
本站文章如未注明出处均为原创,转载请注明出处,如有侵权请邮件联系站长。
0/500
Share your thoughts respectfully.