Home  >  Article  >  Backend Development  >  Discuzx2 development standard process

Discuzx2 development standard process

WBOY
WBOYOriginal
2016-07-29 08:54:571139browse

Studying the source code of discuz x2 for a month. Then I got some development experience. Writing experiences can be considered a kind of review, reviewing the past and learning the new.

First of all, you need to understand the approximate loading process sequence of each root directory page. Here, I won't use the standard files in the root directory. To take a direct example, write a new module and its name is newModule.php.

The process is like this:

1. newModule.php first loads the core class file. /source/class/clsss_core.php is the core class file. This file initializes the core object of the entire dz. Use a single Example mode. The name is $discuz, and this object has several important features. First, the parameters of $_G are referenced to the var attribute of this object, that is, $discuz->var = $_G, and then use $this->var to operate $_G inside the object, and outside the object, For example, in an independent function, $_G is used to operate parameters; secondly, this object references all other objects, including database objects and other objects, and uses references to obtain synchronized changes when operating them within the object. (Actually, this design is originally quite confusing, but it is understandable. In order to take care of the previous design, pure OO PHP design is taboo like this. It is better to use the registry or combination mode)

2. Load the supporting files, /source The /function/function_core.php file contains all core functions. What are core functions? Core functions mean that they will be used when core classes need to be instantiated.

3. The independent functions required to load the module, the /source/function/function_newModule.php file, are independent functions required by the module itself. These functions should not be attributed to a certain function from a logical or business perspective. inside an object or class.

4. Load the module’s customized class file, /source/class/class_newModule.php file. This file is the class required by the new module. This file can create your own extension class, especially domain drivers or OO hobbies. By.

5. Load the module's customized action file. What is an action file? It is the mod in the URL value. The function of this file is to provide the final entry function required by the last new module.

6. After loading the above files, a large piece of php that can be used will be generated. All necessary functions have been prepared, just waiting for ajax or form submission or template display.

One thing to note is: in fact, this is a relatively standard one. It follows the process originally designed by dz and can be seamlessly signed into dz without affecting the functions due to system upgrades. Calm down. Experts are never satisfied, and they usually break away from the dz process. But what about destructiveness? It’s unknown. Needs vary from person to person.

My suggestion is to use OO and a few design patterns to organize the code and streamline the business, so that the scalability is better and the reuse rate is high. Of course, you can play however you like. It's open source. (Actually, the database seems to be well designed. If it were me, I probably wouldn’t be able to design it. Experts please don’t complain.)

The above introduces the standard process of Discuzx2 development, including the content of discuzx2. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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