PHPCMS配置文件的读取
---------------------------------------------------------------------------------------------------
PHPCMS的入口文件index.php里的代码较少,主要做了三件事,如下:
<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();
代码虽少,但是将 做了很多事的框架入口文件base.php加载进来后,等于直接就进入了PHPCMS的核心。
---------------------------@chenwei 黑眼诗人
简单说下base.php主要做的事:
1.定义一系列常量,如框架路径,缓存文件夹路径等,全局可用。
2.加载框架自带函数库,全局可用。
3.通过读取配置文件,将配置值定义为常量,全局可用。
4.自带PHPCMS基类(pc_base),定义了加载系统类,应用类,数据模型,系统函数库,应用函数库,插件类库,插件数据模型,配置文件等的方法。
define('CSS_PATH', pc_base::load_config('system', 'css_path'));
上面定义了CSS路径为常量,以便 前后台的全局使用,那它是如何加载配置文件的,如下方法:
/** <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>
所以在使用load_config()时,只需传入配置文件名 和 配置键,即可获取配置值; 一般获取配置项的原理类似。

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

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

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

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

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

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

Glodon Software is a software company focusing on the field of building informatization. Its products are widely used in all aspects of architectural design, construction, and operation. Due to the complex functions and large data volume of Glodon software, it requires high computer configuration. This article will elaborate on the computer configuration recommendations of Glodon Software from many aspects to help readers choose a suitable computer configuration processor. Glodon Software requires a large amount of data calculation and processing when performing architectural design, simulation and other operations. Therefore, the requirements for the processor are higher. It is recommended to choose a multi-core, high-frequency processor, such as Intel i7 series or AMD Ryzen series. These processors have strong computing power and multi-thread processing capabilities, and can better meet the needs of Glodon software. Memory Memory is affecting computing
