The configuration file component LtConfig in LotusPhp is an important part of the Convention and is suitable for multiple scenarios. Most LotusPhp components, such as databases, caches, RBAC, and form verification, require configuration components, the LtConfig Configuration component is also the base class in the LotusPhp framework.
The content and format of the configuration file will be explained later when talking about the LotusPhp component. This chapter mainly describes the file directory requirements, formats and practical applications of the configuration file.
The LtConfig component has two components: Config. php and ConfigExpression. php In the framework directory.
The configuration file is read, written, and updated through LtConfig. The configuration file is saved in the cache folder defined in the entry file in the form of a text file.
Open the last HelloWorld example and open the folder runtime \ conf.
In the description of the entry file, we have an understanding of several important concepts.
That is, project and application. Generally, an entry file defines a project, and there can be multiple applications under the project. After the LtConfig component is initialized by Lotus, it will first configure the conf folder under the add-on project, in the debugging mode, add the configuration file under standard under the conf directory, load the configuration file under the dev folder, and replace the repeated items, in production mode, the configuration file under the standard folder is loaded. The advantage is that two configurations can be retained locally and in the production environment, and the production mode can be switched online.
After reading the project configuration, the program will continue to load the configuration folder in the application. Let's open \ runtime \ app \ frontend \ conf, and the content of the application configuration file will be called, if there is configuration content with the same name, it will replace the content with the same name in the project configuration file.
In general, the configuration file in the project is mainly a public configuration file, and the configuration file in the application is mainly for private configuration of the application, the configuration files shared by multiple applications should be placed in the configuration folder of the project.
The configuration file writing rules are as follows:
<?] = ] = ;
It must be written as an array and the array variable name must be $ config. Otherwise, it cannot be read.
Now let's modify \ runtime \ app \ frontend \ action \ default-index.php in the HelloWorld DEMO File
<? defaultindexAction ->responseType = 'tpl'->message=LtObjectUtil::singleton('LtConfig')->get('system.name'->data='Hello World!'
Modify the view File \ runtime \ app \ frontend \ view \ default-index.php
{$this->message}{LtObjectUtil::singleton('LtConfig')->get('system.version')}
After saving, run the index. php file to check whether the title bar of the browser has changed.
In this example, we have implemented the method of calling the configuration file in action and the method of calling the configuration file in view.
->message=LtObjectUtil::singleton('LtConfig')->get('system.name'->data=LtObjectUtil::singleton('LtConfig')->get('system.name'::singleton('LtConfig')->get('system.version')}
As for what the LtObjectUtil: singleton class does, we will introduce it in the next chapter.