gongzhonghao.png
扫码关注我们
最新赞助活动温馨提示:自愿赞助服务器费用,学生和没有工作的整站资源免费下载!
头像

THINKPHP支持YAML配置文件的设置方法_php技巧

来源:http://erdangjiade.com/topic/130059.html 你好,世界。 2017-10-04 21:03浏览(6)

为什么要用 yaml

因为 Yaml 简单,而且对人类友好;

Yaml: http://www.yaml.org/

在哪里会用到?

最基本的,在 ThinkPHP 的配置文件里面就可以选择 Yaml 的格式,你是愿意写 Yaml 的简洁格式配置呢?还是愿意写又长又臭又难写的 PHP array 呢?

http://document.thinkerdangjiade.com/manual_3_2.html#config_format

问题来了

于是,我把配置格式改为 Yaml:

复制代码 代码如下:


// /index.php

// 定义配置文件的格式为 yaml
define('CONF_EXT', '.yaml');

然后把 Application 目录下面的 config.php 全部改为 config.yaml。

这个时候,报错:

复制代码 代码如下:


Class ‘Spyc' not found 错误位置 FILE: D:appthinkThinkPHPCommonfunctions.php  LINE: 90


然后找,发现这一段:

复制代码 代码如下:


/**
* 解析yaml文件返回一个数组
* @param string $file 配置文件名
* @return array
*/
if (!function_exists('yaml_parse_file')) {
function yaml_parse_file($file) {
vendor('spyc.Spyc');
return Spyc::YAMLLoad($file);
}
}

貌似引入 Spyc 这个库没找到。

找了一下,Spyc 在这里:https://github.com/mustangostang/spyc/

然后,这个 vendor 是什么东东?

看这里:http://document.thinkerdangjiade.com/manual_3_2.html#autoload

结论:

在上面的 Git 里面下载 Spyc.php 放进 /ThinkPHP/Library/Vendor/spyc/ 目录下,就一切正常!Done with the right way!

评论0
头像

友情提示:垃圾评论一律封号 加我微信:826096331拉你进VIP群学习群

1 2