Eight points of attention for php code architecture: eight points for php architecture. Eight points of attention for the php code architecture. This article summarizes eight points of attention for the php code architecture. I would like to share it with you for your reference. The details are as follows: I wrote code and wrote eight points of attention for the php code architecture in six years. The php architecture was eight points of attention.
This article summarizes the eight-point notes for php code architecture. We will share this with you for your reference. The details are as follows:
I have been writing code for more than six years. let's look at the previous architecture and the current architecture. There are some shortcomings. In any case, they have been improving. To tell the truth, I don't like to use Frameworks. basically, all the frameworks are similar, but they are not much different. if you want to use them, you need to understand ideas, directory structures, file calls, and file names, code specifications are a waste of time. The architecture can meet a large part of the requirements. the more people that meet the requirements, the worse the performance. this is one of the main reasons why I don't like the architecture. Let's talk about the code architecture.
1. mainly object-oriented, supplemented by process-oriented
Php4 is process-oriented, and php5 and later support object-oriented.
1. object-oriented programming, code management, reasonable planning, and better performance.
2. for process code management, the planning is relatively simple, the calling method is more direct, clearer, and the efficiency is relatively poor.
For example:
Object-oriented is like a software park. if you want to find the location of a company, you need to know the number of buildings, floors, and rooms.
The process is like a civilian zone. if you want to find a household, you need to know the path and number.
If you want to change the high buildings in the software park into houses, you need to occupy more land. If the park is too large, it is not cheap to find it. it is much easier to find a separate consulting room. Therefore, I personally think that a good architecture must be mainly object-oriented and process-oriented.
II. directory structure planning
This is very important in code architecture. it is like a building in a software park. it cannot be built without authorization. Where are the entry files, functional modules, and template files. In a word, the configuration file, JS file, php file, module file, CSS file, and image file are arranged.
3. single or multiple portals
Currently, the php framework I know and CMS are basically single-entry. Single Portal or multiple portals, each of which has its own advantages. One thing to mention is that a single portal is definitely better than multiple portals, and the url is rewritten.
IV. object-oriented hierarchical design
Generally, three levels are enough. The underlying class, the underlying module class, and the application class of the combination module. For a relatively large website, there will be more levels.
5. plan the database class
This is very important. the ideal way is to execute all SQL statements in one class. This is a long-term plan. mysql clusters or nosql such as memcache will be used in the future. if SQL is everywhere, it will be depressing.
6. Category sharing under multiple second-level domain names
What do you mean? for example, a website has three directories: BBS, Portal, Weibo, and normal thinking (except discuz, so the second-level domain name points to the same directory, that is to say, there are three documentroot, and the shared class is best left out of the web directory. Such classes can be shared to reduce code redundancy.
VII. Use template plug-ins
Php code and html code are mixed and I don't think it is good, especially the website revision will make you crash. Currently, php code and html are separated by many templates, such as smarty.
VIII. js code planning
Smarty can separate php and html, and jquery and other similar js plug-ins can separate js and html. Js is also a development language. JS-based plug-ins can also be understood as a language, which can be divided into object-oriented and process-oriented. If you do not plan well, the html page will be messy. you can view the source code and find that half of the html and half of the JS.