Home Backend Development PHP Tutorial THINKPHP支持YAML配置文件的设置方法_php技巧

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

May 16, 2016 pm 08:20 PM
thinkphp yaml Configuration

为什么要用 yaml

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

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

在哪里会用到?

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

http://document.thinkphp.cn/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:\app\think\ThinkPHP\Common\functions.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.thinkphp.cn/manual_3_2.html#autoload

结论:

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

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

The working principle and configuration method of GDM in Linux system The working principle and configuration method of GDM in Linux system Mar 01, 2024 pm 06:36 PM

The working principle and configuration method of GDM in Linux system

The perfect combination of PyCharm and PyTorch: detailed installation and configuration steps The perfect combination of PyCharm and PyTorch: detailed installation and configuration steps Feb 21, 2024 pm 12:00 PM

The perfect combination of PyCharm and PyTorch: detailed installation and configuration steps

Understand Linux Bashrc: functions, configuration and usage Understand Linux Bashrc: functions, configuration and usage Mar 20, 2024 pm 03:30 PM

Understand Linux Bashrc: functions, configuration and usage

How to run thinkphp project How to run thinkphp project Apr 09, 2024 pm 05:33 PM

How to run thinkphp project

There are several versions of thinkphp There are several versions of thinkphp Apr 09, 2024 pm 06:09 PM

There are several versions of thinkphp

How to run thinkphp How to run thinkphp Apr 09, 2024 pm 05:39 PM

How to run thinkphp

How to install thinkphp How to install thinkphp Apr 09, 2024 pm 05:42 PM

How to install thinkphp

MyBatis Generator configuration parameter interpretation and best practices MyBatis Generator configuration parameter interpretation and best practices Feb 23, 2024 am 09:51 AM

MyBatis Generator configuration parameter interpretation and best practices

See all articles