Home > PHP Framework > ThinkPHP > body text

How to load other types of configuration files in ThinkPHP

咔咔
Release: 2020-10-09 16:05:01
Original
1635 people have browsed it

All configuration file types in the framework are PHP files, so how do we enable it to load other types of extensions! This article is only an extension and it is not recommended to change the framework source code.

7. Loading other types of configuration files in factory mode

The loadFile method we saw before If the file type is PHP or yaml, the program will be interrupted and the subsequent pares method will not be executed.

So what does this parse method do?

How to load other types of configuration files in ThinkPHPAfter entering the paras method, first read the comments

Then use a factory mode to load the files under think/config/driver

How to load other types of configuration files in ThinkPHP After entering the factory method, there is no need to explain too much that this content belongs to the container.

You only need to know that an instance will eventually be returned to the $object variable of the paras method.

How to load other types of configuration files in ThinkPHPIn the end, the set method mentioned above will be used, and The internal object->parse() is an internal method that executes the returned object. For example, the following figure shows three types. The same methods exist in the three types of ini, json, and xm

How to load other types of configuration files in ThinkPHPThis is the ini type. The other two types are exactly the same, that is, they will have the same method to implement the corresponding functions.

How to load other types of configuration files in ThinkPHP
Insert picture description here

Briefly sort out the different types of configurations loaded by the factory mode

  • Pass the corresponding type to a method
  • Then this method returns the corresponding instance
  • Use this instance to call the method in the class
  • All instances The method names in are all the same

Here Kaka will publish a separate article later to imitate this to achieve another function, and the map will have links to all articles!

I saw a method parse_ini_file in ini.php. In fact, based on previous study, you can probably understand this method to convert the ini type configuration file into an array form. I won’t do a demonstration here, it’s very simple!

The other two types are for converting file data into arrays.

Persistence in learning, persistence in blogging, and persistence in sharing are the beliefs that Kaka has always adhered to since its beginning. I hope that Kaka’s articles on the huge Internet can bring you a little bit of help. I’m Kaka, see you next time.

The above is the detailed content of How to load other types of configuration files in ThinkPHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template