Reading PHPCMS configuration file_PHP tutorial
-------------------------------------------------- -------------------------------------------------- -----
PHPCMS’s entry file index.php contains less code and mainly does three things, as follows:
<span>//</span><span>1.定义PHPCMS根目录(入口文件所在目录),PHPCMS_PATH全局可用</span> <span>define</span>('PHPCMS_PATH', <span>dirname</span>(<span>__FILE__</span>).<span>DIRECTORY_SEPARATOR) </span><span>//</span><span>2.引入框架入口文件(与入口文件同级的框架目录phpcms中的base.php)</span> <span>include</span> PHPCMS_PATH.'/phpcms/base.php'<span>; </span><span>//</span><span>3.调用框架入口文件中基类pc_base的静态方法create_app(),进行应用程序初始化</span> pc_base::create_app();
Although the code is small, after loading the framework entry file base.php that does a lot of things, it is equivalent to directly entering the core of PHPCMS.
--------------------------@chenwei Black-eyed Poet
Let’s briefly talk about the main things base.php does:
1. Define a series of constants, such as framework path, cache folder path, etc., which are globally available.
2. The loading framework comes with its own function library, which is available globally.
3. By reading the configuration file, define the configuration value as a constant, which is globally available.
4. Comes with the PHPCMS base class (pc_base), which defines methods for loading system classes, application classes, data models, system function libraries, application function libraries, plug-in class libraries, plug-in data models, configuration files, etc.
define('CSS_PATH', pc_base::load_config('system', 'css_path'));
The above defines the CSS path as a constant for global use in the front and backend, so how does it load the configuration file, as follows:
/** <br /> * 加载配置文件 <br /> * @param string $file 配置文件 <br /> * @param string $key 要获取的配置键 <br /> * @param string $default 默认配置。当获取配置项目失败时该值发生作用。 <br /> * @param boolean $reload 强制重新加载。 <br /> */<br /><span> public</span> <span>static</span> <span>function</span> load_config(<span>$file</span>, <span>$key</span> = '', <span>$default</span> = '', <span>$reload</span> = <span>false</span><span>) { </span> <span>static</span> <span>$configs</span> = <span>array</span><span>(); <span><span>//<span># 定义存放配置值的空数组</span></span></span><br /><br /></span> //----------------------------------------- <span>if</span> (!<span>$reload</span> && <span>isset</span>(<span>$configs</span>[<span>$file</span><span>])) { <span>//<span># 如果重新加载 且 设置了$configs[$file](这里不执行)</span></span></span> <span>if</span> (<span>empty</span>(<span>$key</span><span>)) {</span> <span>return</span> <span>$configs</span>[<span>$file</span><span>]; <span>//<span># <span><span><span>如果配置键为空,返回整个配置数组(配置文件以一维数组形式返回,如:return array('a'=>'','b'=>''))</span></span></span></span></span> } </span><span>elseif</span> (<span>isset</span>(<span>$configs</span>[<span>$file</span>][<span>$key</span><span>])) { </span> <span>return</span> <span>$configs</span>[<span>$file</span>][<span>$key</span><span>]; <span><span>//<span># 如果设置了有配置键的值,返回</span></span></span> } </span><span>else</span><span> {</span> <span>return</span> <span>$default</span><span>; <span><span>//<span># 默认返回配置default</span></span></span> } }<br /> //----------------------------------------- </span> <span>$path</span> = CACHE_PATH.'configs'.DIRECTORY_SEPARATOR.<span>$file</span>.'.php'<span>;<span>//<span># 系统配置文件路径,$path = PHPCMS_PATH.'caches/configs/system.php';</span></span></span> <span>if</span> (<span>file_exists</span>(<span>$path</span><span>)) {</span> <span>$configs</span>[<span>$file</span>] = <span>include</span> <span>$path</span><span>; <span><span><span>//<span># 如果system配置文件存在,引入</span></span></span></span> } </span> <span>if</span> (<span>empty</span>(<span>$key</span><span>)) { <span><span><span><span>//<span># 根据$key取配置值,否则返回default值,同上虚线间代码</span></span></span></span></span></span> <span>return</span> <span>$configs</span>[<span>$file</span><span>]; } </span><span>elseif</span> (<span>isset</span>(<span>$configs</span>[<span>$file</span>][<span>$key</span><span>])) {</span> <span>return</span> <span>$configs</span>[<span>$file</span>][<span>$key</span><span>]; } </span><span>else</span><span> {</span> <span>return</span> <span>$default</span><span>; } }</span>
So when using load_config(), you only need to pass in the configuration file name and configuration key to obtain the configuration value; generally, the principle of obtaining configuration items is similar.

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











How to set up keyboard startup on Gigabyte's motherboard. First, if it needs to support keyboard startup, it must be a PS2 keyboard! ! The setting steps are as follows: Step 1: Press Del or F2 to enter the BIOS after booting, and go to the Advanced (Advanced) mode of the BIOS. Ordinary motherboards enter the EZ (Easy) mode of the motherboard by default. You need to press F7 to switch to the Advanced mode. ROG series motherboards enter the BIOS by default. Advanced mode (we use Simplified Chinese to demonstrate) Step 2: Select to - [Advanced] - [Advanced Power Management (APM)] Step 3: Find the option [Wake up by PS2 keyboard] Step 4: This option The default is Disabled. After pulling down, you can see three different setting options, namely press [space bar] to turn on the computer, press group

1. Processor When choosing a computer configuration, the processor is one of the most important components. For playing games like CS, the performance of the processor directly affects the smoothness and response speed of the game. It is recommended to choose Intel Core i5 or i7 series processors because they have powerful multi-core processing capabilities and high frequencies, and can easily cope with the high requirements of CS. 2. Graphics card Graphics card is one of the important factors in game performance. For shooting games such as CS, the performance of the graphics card directly affects the clarity and smoothness of the game screen. It is recommended to choose NVIDIA GeForce GTX series or AMD Radeon RX series graphics cards. They have excellent graphics processing capabilities and high frame rate output, and can provide a better gaming experience. 3. Memory power

How to use pandas to read txt files correctly requires specific code examples. Pandas is a widely used Python data analysis library. It can be used to process a variety of data types, including CSV files, Excel files, SQL databases, etc. At the same time, it can also be used to read text files, such as txt files. However, when reading txt files, we sometimes encounter some problems, such as encoding problems, delimiter problems, etc. This article will introduce how to read txt correctly using pandas

If you bought your laptop from a mobile operator, you most likely had the option to activate an eSIM and use your cellular network to connect your computer to the Internet. With eSIM, you don't need to insert another physical SIM card into your laptop because it's already built-in. It is very useful when your device cannot connect to the network. How to check if my Windows 11 device is eSIM compatible? Click the Start button and go to Network & Internet > Cellular > Settings. If you don't see the "Cellular" option, your device doesn't have eSIM capabilities and you should check another option, such as using your mobile device to connect your laptop to a hotspot. In order to activate and

SPDIFOUT connection line sequence on the motherboard. Recently, I encountered a problem regarding the wiring sequence of the wires. I checked online. Some information says that 1, 2, and 4 correspond to out, +5V, and ground; while other information says that 1, 2, and 4 correspond to out, ground, and +5V. The best way is to check your motherboard manual. If you can't find the manual, you can use a multimeter to measure it. Find the ground first, then you can determine the order of the rest of the wiring. How to connect motherboard VDG wiring When connecting the VDG wiring of the motherboard, you need to plug one end of the VGA cable into the VGA interface of the monitor and the other end into the VGA interface of the computer's graphics card. Please be careful not to plug it into the motherboard's VGA port. Once connected, you can

Practical tips for reading txt files using pandas, specific code examples are required. In data analysis and data processing, txt files are a common data format. Using pandas to read txt files allows for fast and convenient data processing. This article will introduce several practical techniques to help you better use pandas to read txt files, along with specific code examples. Reading txt files with delimiters When using pandas to read txt files with delimiters, you can use read_c

The practical method of reading web page data in Pandas requires specific code examples. During data analysis and processing, we often need to obtain data from web pages. As a powerful data processing tool, Pandas provides convenient methods to read and process web page data. This article will introduce several commonly used practical methods for reading web page data in Pandas, and attach specific code examples. Method 1: Use the read_html() function. Pandas’ read_html() function can read directly from the web page.

Example of using OpenCSV to read and write CSV files in Java. CSV (Comma-SeparatedValues) refers to comma-separated values and is a common data storage format. In Java, OpenCSV is a commonly used tool library for reading and writing CSV files. This article will introduce how to use OpenCSV to implement examples of reading and writing CSV files. Introducing the OpenCSV library First, you need to introduce the OpenCSV library to
