ThinkPHP3.2.2 use yaml configuration format

Source: Internet
Author: User
Tags composer install
Provides various official and user-released code examples. For code reference, you are welcome to learn ThinkPHP3.2.2 how to use the yaml configuration format to report errors
I haven't used ThinkPHP development for a long time. I have a small project to be developed and want to use ThinkPHP for development. So I downloaded ThinkPHP3.2.2 and found a composer. I am really happy to see this file in the json file, because it is much easier to manage third-party Code. For more information about composer, visit the composer official website, visit my blog Composer to help you easily manage the PHP package.

Another thing that made me better off was ThinkPHP3.2.2. yaml/json/xml/ini and custom format support were added to the configuration file. I prefer to use yaml format to configure some information, yes. I have added it to the main portal file according to the official documentation. // Define the configuration format
Define ('conf _ EXT ','. yaml ');
Execute the main entry file and remind me to Call to undefined function yaml_parse_file (). According to the prompt information, the yaml_parse_file () function was not officially provided.

Parsing yaml has a mature spyc class that not only parses files in yaml format into PHP arrays, but also parses PHP arrays into yaml. Spyc

My solution is:
1. Create composer. json in your project directory {
"require": {
"topthink/thinkphp": "dev-master",
"mustangostang/spyc": "0.5.*@dev"
}
}
2. Installation Package # composer install3. Create index. php $ Loader = require 'vendor/autoload. php ';

// Application entry file

// Check the PHP Environment
If (version_compare (PHP_VERSION, '5. 3.0 ',' <') die ('require PHP> 5.3.0! ');

// Enable the debugging mode. We recommend that you enable the annotation of the deployment phase in the development phase or set it to false.
Define ('app _ debug', True );

// Define the application directory
Define ('app _ path', './Application /');

// Define the configuration format
Define ('conf _ EXT ','. yaml ');

Function yaml_parse_file ($ file ){
Return Spyc: YAMLLoad ($ file );
}

// Introduce the ThinkPHP entry file
Require './vendor/topthink/thinkphp/ThinkPHP. php ';

// It's so simple that no code is needed in the end of ^_^
4. Done.

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.