Discuzx2开发标准流程,discuzx2开发流程
研究了有一个月的discuz x2的源代码。然后有了一些开发的心得。写心得也算是一种回顾,温故而知新嘛。
首先,要理解每一个根目录页面的大概的加载流程顺序。这里,我就不用根目录的标准文件了。直接举例,写一个新的模块,它的名字叫做newModule.php。
流程是这样的:
1. newModule.php首先加载核心的类文件,/source/class/clsss_core.php这个是核心的类文件,这个文件是初始化了整个dz的核心对象,用了单例模式。名字叫做$discuz,这个对象里面有几个比较重要的特点。首先,是$_G的参数,被引用到了这个对象的var属性中,也就是$discuz->var = $_G,然后在对象内用$this->var来操作$_G,在对象外面,比如独立函数中,使用$_G来操作参数;其次是这个对象里面引用了所有的其他对象,包括数据库对象和其他对象,都是用引用来获得在对象内操作的它们时的同步改变。(其实这个设计原本就比较混乱,不过可以理解,为了照顾以前的设计,纯OO的php设计是忌讳这样的,应该使用注册表或者组合模式来得更好)
2. 加载支持文件,/source/function/function_core.php文件是所有核心函数,何谓核心函数,核心函数的意思就是在核心类需要实例化的时候,它们就会被使用到。
3. 加载模块所需要的独立函数, /source/function/function_newModule.php文件,是该模块自己所需要的独立的函数,这些函数应该是从逻辑或者是业务上来说是不能被归结到某个对象或者类里面。
4. 加载模块自定义的类文件,/source/class/class_newModule.php文件,这个文件是新模块所需要用到类,这个文件可以创建自己的扩展类,特别是领域驱动,或者OO爱好者。
5. 加载模块自定义的动作文件,什么叫动作文件,就是url传值中的mod,这文件的作用是,如果提供最后这个新模块所需要的最终入口函数。
6. 加载完以上文件,那么,就可以产生了一个可以供用来使用的大块php的。所有的必须要的函数都已经准备,就等着ajax或者form的提交或者template的显示。
需要注意一点是:其实这里是一个比较标准的,遵从dz原本设计的流程,可以无缝的内签到dz中,而不会因为系统升级从来影响功能。淡然了。高手们从来都不满足的,他们一般都会脱离dz的流程。不过,破坏性怎么样?就不得而知了。需要因人而异。
我的建议是使用OO和少许的设计模式,来组织代码,理顺业务,这样扩展性较好,复用率高。当然,喜欢怎么玩,就怎么玩。开源的嘛。(其实数据库感觉设计的可以,如果是我,想必设计不出来,高手勿喷。)

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

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

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