Eight points of attention to PHP code architecture _php Tips

Source: Internet
Author: User
Tags html page php code php framework

This article summarizes eight points to note about the PHP code architecture. Share to everyone for your reference, specific as follows:

Write code for more than 6 years, look at the previous architecture, look at the current architecture. There are a few inadequacies here. In any case, it has been improving. Honestly don't like to use the framework of such things, basically all the framework are similar, not much, to use words, you have to understand the idea, directory structure, file calls, file naming, code specifications, etc., quite a waste of time. Architecture can meet a large part of the requirements, the more people meet the performance of the worse, which I do not like to use the structure of a major reason. Here are some of the code architecture aspects of the heart.

One, object oriented, process-oriented supplement

PHP4 is a process-oriented, PHP5 and later supporting object-oriented.

1, object-oriented program design idea, for code management, planning more reasonable, better performance and so on.
2, for Process code management, planning is simpler, the way to call more direct, more clearly, the efficiency is relatively poor.
For example, explain:
Object-oriented is like a software park, if you want to find the location of a company, you need to know what floor, a few floors, a few rooms.
Process-oriented is like a civilian area, if you want to find a family, you know, what road, number on the line.
If you want to turn the software Park high-rise into a house, it is necessary to occupy more land. If the park is too large, it is not cheap to find, if a separate consultation room is much more convenient. So personally feel, a good structure, must be oriented to object-oriented, process-oriented supplement.

Ii. Planning of directory structure

Code architecture, this is very important, this is like the building of Software park, can not be arbitrarily covered, have a regular. Where the entry files are placed, where the functional modules are placed, and where the template files are placed. In a word, arranged, configuration files, JS files, php files, module files, CSS files, picture files and so on.

Three, a single entrance or multiple entrances

Currently I understand the PHP framework, or CMS is basically a single entry. Single or multiple entrances, each with its own good. One point to mention a single entry is definitely better than multiple entrances, the URL rewrite.

Iv. object-oriented Hierarchical Design

Under normal circumstances, basically three level is enough, the bottom class, basic low-level module class, modular Application class. If it is a relatively large site, the level of points will be more.

Five, the database class to plan well

This is important, ideally, for all SQL execution to walk a class. Why to do this, this is for the long-term plan, the future to do the MySQL cluster, or the use of memcache such as NoSQL, conversion is also convenient, if the SQL everywhere, it is depressed.

Six, more than two class domain name under the common use

What do you mean, for example, a website has, BBS, portal, Weibo, normal thinking (except Discuz, so two-level domain name points to the same directory) is corresponding to three directories, that is, there are three documentroot, the common class is best to break out of the web directory and exist. Such classes can be shared and can reduce code redundancy.

The use of template Plug-ins

PHP code and HTML code mixed write, I feel bad, especially the website revision, will let you crash. Now the PHP code and HTML separate template a lot of, for example: Smarty

Eight, JS code planning

Smarty can make PHP and HTML separate, jquery and other similar JS plug-ins can make JS and HTML separate. JS is also a development language, based on JS Plug-ins can also be understood as a language, there are object-oriented and process-oriented points. If you do not plan well, the HTML page will be very messy, see the source code will find that half of the HTML, half JS.

For more information about PHP interested readers can view the site topics: "Introduction to PHP Basic Grammar", "PHP object-oriented Programming Program Introduction" and "PHP Excellent Development Framework Summary"

I hope this article will help you with the PHP program design.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.