Home php教程 php手册 【23】 Implementation of user-defined extension functions

【23】 Implementation of user-defined extension functions

Nov 30, 2016 pm 11:59 PM

In the previous tutorial, we have implemented the public configuration items. In this section we will implement user-defined extension functions. We all know that although many functions and various classes have been defined in the framework, sometimes it does not fully meet our needs, so we need to introduce self-defined classes and functions.

1. Add configuration to the framework configuration file config.php

//载入Common/Lib目录下的文件,可以载入多个
Copy after login
'AUTO_LOAD_FILE'=><span style="color: #0000ff">array</span>(),
Copy after login

2. Define a private static method in the Application class file to use the C function to read the user-defined configuration file and load it in a loop, as follows:

private static function _import_user_file(){
		$fileArr=C('AUTO_LOAD_FILE');
		if(is_array($fileArr) || !empty($fileArr)){
			foreach ($fileArr as $v) {
				require_once COMMON_LIB_PATH.'/'.$v;
			}
			
		}
	}
Copy after login

 

3. Call the run method of the Application class file

//载入用户自定义的文件
Copy after login
self::_import_user_file();
Copy after login

4. Users write custom functions or classes and place them under the Common/Lib directory in the root directory, such as function1.php, People.class.php

5. Configure user-defined files in the public configuration file Common/Config/config.php

'AUTO_LOAD_FILE'=><span style="color: #0000ff">array</span>('function1.php','People.class.php'),
Copy after login

6. Call function methods or instantiate classes in the controller

<span style="color: #008000">//</span><span style="color: #008000">类</span>
<span style="color: #800080">$peopleobj</span>=<span style="color: #0000ff">new</span><span style="color: #000000"> People();
</span><span style="color: #800080">$peopleobj</span>-><span style="color: #000000">run();

</span><span style="color: #008000">//</span><span style="color: #008000">函数</span>
p(<span style="color: #800080">$_SERVER</span>);
Copy after login

At this point, the user-defined extension function has been implemented. Thanks to Mr. Wangma’s tutorial...

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)