当前位置:网站首页>thinkphp5中的配置如何使用
thinkphp5中的配置如何使用
2022-06-29 19:57:00 【全栈程序员站长】
thinkphp5中的配置如何使用
一、总结
一句话总结:先加载配置,然后读取配置即可
加载配置 读取配置
Config::load(APP_PATH.'fry_config.php');\\加载配置
config("student_can_check_dif_group");\\读取配置1、Config::load(APP_PATH.‘fry_config.php’)加载自建配置文件fry_config.php,到底加载了哪些配置,只有fry_config.php里面的内容么?
其它配置文件 内容
配置文件fry_config.php中的内容如下
也就是我们在配置文件中添加了一条 student_can_check_dif_group 的配置
1 <?php 2 3 //老師相關功能的系統配置 4 return [ 5 //是否允許小組之間互相查看筆記情況: 6 'student_can_check_dif_group' =>false, 7 8 ];其实还有系统自带配置文件config.php中的内容
$fry_config=Config::load(APP_PATH.'fry_config.php');
dump($fry_config);die;看着两句代码的输出结果便知:
2、如何使用配置?
加载配置 读取配置
先加载配置,然后读取配置即可
Config::load(APP_PATH.'fry_config.php');\\加载配置
dump(config("student_can_check_dif_group"));\\读取配置这两句话的结果为:
bool(false)如上结果正确获取了配置文件
不加载配置,直接读取配置效果
dump(config("student_can_check_dif_group"));\\读取配置直接运行这句话,结果为:
NULL3、助手函数config(“student_can_check_dif_group”,true)可修改配置字段为true,这样修改之后fry_config.php中的student_can_check_dif_group字段的值是否改变?
没
并没有改变
4、测试配置代码及效果?
方法
1 //是否允許不同小組之間互相查看
2 public function canDifGroupCheckAns(){
3 //$fry_config=Config::load(APP_PATH.'fry_config.php');
4 Config::load(APP_PATH.'fry_config.php');
5 dump(config("student_can_check_dif_group"));
6 config("student_can_check_dif_group",true);
7 dump(config("student_can_check_dif_group"));
8 //dump($fry_config);die;
9 }5、用配置文件实现 老师 控制学生小组之间是否可以查看不同小组资料 这个操作是否合理?
不合理
数据库
并不合理,因为配置的修改不能修改配置文件本身,这样会导致每次服务器重启,这个功能就被初始化了,比如配置文件设置的false,老师页面点击按钮修改为 true之后,服务器重启,这个被初始化为false,这并不是我们预期的效果
所以这个功能用数据库实现比较好
二、thinkphp5中的配置如何使用
1、创建配置文件
2、配置文件fry_config.php中的内容如下
也就是我们在配置文件中添加了一条 student_can_check_dif_group 的配置
1 <?php
2
3 //老師相關功能的系統配置
4 return [
5 //是否允許小組之間互相查看筆記情況:
6 'student_can_check_dif_group' =>false,
7
8 ];3、如何使用和修改这条配置
需要加载配置之后才能正常使用
使用配置代码如下:
config("student_can_check_dif_group");修改配置代码如下(比如我们要将值修改为true):
config("student_can_check_dif_group",true)并且修改配置只能修改内存值,修改不了文件中的值,
比如我在这里将student_can_check_dif_group从false改成了true,但是我文件fry_config中还是false。
不过在系统其它调用这个配置的位置变成了true,但是文件中还是false。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/101319.html原文链接:https://javaforall.cn
边栏推荐
- One hour to build a sample scenario sound network to release lingfalcon Internet of things cloud platform
- Etcd database source code analysis - put process of server
- Flume theory
- Sword finger offer 59 - I. maximum value of sliding window
- Linux Installation mysql5
- 一个超赞的开源的图片去水印解决方案
- Tiger painter mengxiangshun's digital collection is on sale in limited quantities and comes with Maotai in the year of the tiger
- MSYQL, redis, mongodb visual monitoring tool grafana
- 以其他组件为代价的性能提升不是好提升
- NLP - giza++ implements word alignment
猜你喜欢

Flume configuration 3 - interceptor filtering
![[boutique] detailed explanation of Pinia](/img/94/d332e32dba54be3c2d3f6ff08a85fa.png)
[boutique] detailed explanation of Pinia

Real time tracking of bug handling progress of the project through metersphere and dataease

一次 Keepalived 高可用的事故,让我重学了一遍它!

npm ERR! fatal: early EOF npm ERR! fatal: index-pack failed

There is no small green triangle on the method in idea

Shell bash script note: there must be no other irrelevant characters after the escape character \ at the end of a single line (multi line command)

一个mysql里有3306端口下,一个mysql有20多个数据库,怎么一键备份20多个数据库,做系统备份,防止数据误删除?

Flume理论

【精品】pinia详解
随机推荐
Dynamics CRM: 本地部署的服务器中, Sandbox, Unzip, VSS, Asynchronous还有Monitor服务的作用
Flume配置3——拦截器过滤
Zotero期刊自动匹配更新影响因子
Zotero journal Automatic Matching Update Influencing Factors
Flume理论
雪花id,分布式唯一id
There are more than 20 databases in a MySQL with 3306 ports. How can I backup more than 20 databases with one click and do system backup to prevent data from being deleted by mistake?
Flume配置2——监控之Ganglia
One hour to build a sample scenario sound network to release lingfalcon Internet of things cloud platform
freemarker模板框架生成图片
软件测试逻辑覆盖相关理解
What about frequent network disconnection of win11 system? Solution to win11 network instability
Mba-day19 if P then q contradictory relation P and not Q
测试方法学习
npm ERR! fatal: early EOF npm ERR! fatal: index-pack failed
Flume-ng配置
Jmeter之BeanShell详解和夸线程调用
Understanding of software test logic coverage
剑指 Offer 59 - II. 队列的最大值
[network orientation training] - Enterprise Park Network Design - [had done]