


If you don't study the source code of ThinkPHP, how will you know the role of the env file?
This article mainly introduces the framework's use of env files to load other types of configuration files. A previous article introduced the factory mode loading of configuration files.
9. How to let the framework load other types of configuration files using env files
When initializing the application There is an attribute in the module called configExt. This attribute is the extension of the file.
Find where this attribute is set.
According to the config configuration file loading process, you can clearly see that the upper layer of the init
method is the initialization application, which is the initialize
method.
Then this attribute must have been set in advance before the init
method.
Return to the previous level of the init
method initialize
and you can directly see the setting of this value.

This value is obtained from the environment variable of env. If not, it defaults to php, so you need to create an env file. .
And give a default value of yaml
Let me show you the changes. There is a bug in the 5.1.34 LTS version. Kaka is currently using 5.1.39 LTS This issue has been fixed.
I believe you can all see this code. It first sets the default value for configExt, and then loads the environment variable configuration file.
Then the code to load this environment variable is meaningless. The value of configExt will always be .php
Even if the configuration is made in the env file, it will not be obtained.
A yaml configuration file was added to the config configuration file before
Then at this time, you can use the config class to obtain the configuration of the yaml type file.
There is no problem after testing, the data can come out.
But we don’t dare to do this in actual projects! If you want to configure the value configExt
to the environment variable, you need to convert all configuration files in the config directory to the corresponding type.
For example, if configExt is set to .ini, then all files in the config directory need to be changed to ini file format
This content is only for the application after reading the source code. Do not use it in actual projects because all configuration files in the tp framework are of PHP type.
If you change it to other types, you will need to modify all the configuration files in the framework. It would be a shame if you can do this!
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 If you don't study the source code of ThinkPHP, how will you know the role of the env file?. For more information, please follow other related articles on the PHP Chinese website!

The article discusses ThinkPHP's built-in testing framework, highlighting its key features like unit and integration testing, and how it enhances application reliability through early bug detection and improved code quality.

Article discusses using ThinkPHP for real-time stock market data feeds, focusing on setup, data accuracy, optimization, and security measures.

The article discusses key considerations for using ThinkPHP in serverless architectures, focusing on performance optimization, stateless design, and security. It highlights benefits like cost efficiency and scalability, but also addresses challenges

The article discusses implementing service discovery and load balancing in ThinkPHP microservices, focusing on setup, best practices, integration methods, and recommended tools.[159 characters]

ThinkPHP's IoC container offers advanced features like lazy loading, contextual binding, and method injection for efficient dependency management in PHP apps.Character count: 159

The article discusses using ThinkPHP to build real-time collaboration tools, focusing on setup, WebSocket integration, and security best practices.

ThinkPHP benefits SaaS apps with its lightweight design, MVC architecture, and extensibility. It enhances scalability, speeds development, and improves security through various features.

The article outlines building a distributed task queue system using ThinkPHP and RabbitMQ, focusing on installation, configuration, task management, and scalability. Key issues include ensuring high availability, avoiding common pitfalls like imprope


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

WebStorm Mac version
Useful JavaScript development tools

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.