The configuration file component LtConfig in LotusPhp is an important part of the agreement and is suitable for multiple scenarios. Most LotusPhp components such as database, cache, RBAC, form verification, etc. need to use the configuration component, LtConfig configuration component It is also the base class in the LotusPhp framework.
When explaining LotusPhp components in the future, the content and format of the configuration file will be explained. This chapter mainly talks about the file directory requirements, format and practical application of the configuration file.
The LtConfig component has 2 components, Config.php and ConfigExpression.php in the framework directory
The configuration file is mainly read, written, and updated through LtConfig, and the configuration file is saved in the cache folder defined by the entry file in the form of a text file
Please open the last HelloWorld example and open the folder runtimeconf
In the explanation of the entry file, we have an understanding of several important concepts
That is projects and applications. Generally speaking, an entry file defines a project. There can be multiple applications under the project. After Lotus is initialized, the LtConfig component will first load the conf configuration folder under the project. If it is in debugging mode, First add the configuration file under standard in the conf directory, then load the configuration file under the dev folder and replace the duplicates. In production mode, load the configuration file under the standard folder. The advantage of this is that it can be used in both local and production environments. Keep 2 configurations and switch to production mode online
After reading the project configuration, the program will continue to load the configuration folder in the application. Let us open runtimeappfrontendconf. The application configuration file content will be called. If there is a configuration content with the same name, it will replace the same name in the project configuration file. content.
Generally speaking, the configuration files in the project are mainly public configuration file contents, while the configuration files in the application are mainly for application-private configurations. Configuration files shared by multiple applications should be placed in the project configuration folder. Medium
The configuration file writing specifications are as follows
<?<span php $config[</span><span '</span><span system.version</span><span '</span>] = <span '</span><span 1.0</span><span '</span><span ; $config[</span><span '</span><span system.name</span><span '</span>] = <span '</span><span LotusPhp网站管理系统</span><span '</span>;
must be written in the form of an array, and the array variable name is forced to be $config, otherwise it cannot be read
Now let’s modify runtimeappfrontendactiondefault-index.php in the HelloWorld DEMO file
<?<span php </span><span class</span> defaultindexAction <span extends</span><span LtAction { </span><span public</span> <span function</span><span execute() { </span><span $this</span>->responseType = 'tpl'<span ; </span><span $this</span>->message=LtObjectUtil::singleton('LtConfig')->get('system.name'<span ); </span><span $this</span>->data='Hello World!'<span ; } }</span>
Then modify the view file runtimeappfrontendviewdefault-index.php
<span <!</span><span doctype html</span><span ></span> <span <</span><span html</span><span ></span> <span <</span><span head</span><span ></span> <span <</span><span meta </span><span charset</span><span ="utf-8"</span><span ></span> <span <</span><span title</span><span ></span>{$this->message}{LtObjectUtil::singleton('LtConfig')->get('system.version')}<span </</span><span title</span><span ></span> <span </</span><span head</span><span ></span> <span <</span><span body</span><span ></span><span {$this->data} </span><span </</span><span body</span><span ></span> <span </</span><span html</span><span ></span>
After saving, run the index.php file and see if there are any changes in the browser title bar
In this example, we have practiced the method of calling the configuration file in the action and the method of calling the configuration file in the view. Let’s review it again
<span action中调用配置文件: </span><span $this</span>->message=LtObjectUtil::singleton('LtConfig')->get('system.name'<span ); 或者 </span><span $this</span>->data=LtObjectUtil::singleton('LtConfig')->get('system.name'<span ); view中调用配置文件: {LtObjectUtil</span>::singleton('LtConfig')->get('system.version')}
As for what the LtObjectUtil::singleton class does, we will introduce it in the next chapter