THINKPHP支援YAML設定檔的設定方法_php技巧

來源:互聯網
上載者:User

為什麼要用 yaml

因為 Yaml 簡單,而且對人類友好;

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

在哪裡會用到?

最基本的,在 ThinkPHP 的設定檔裡面就可以選擇 Yaml 的格式,你是願意寫 Yaml 的簡潔格式配置呢?還是願意寫又長又臭又難寫的 PHP array 呢?

http://document.thinkphp.cn/manual_3_2.html

問題來了

於是,我把配置格式改為 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

結論:

在上面的 Git 裡面下載 Spyc.php 放進 /ThinkPHP/Library/Vendor/spyc/ 目錄下,就一切正常!Done with the right way!

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.