PHP Code architecture Eight points of caution, PHP architecture eight point _php Tutorial

Source: Internet
Author: User
Tags php framework

PHP Code Architecture Eight points of note, PHP architecture eight points


This article summarizes eight considerations for the PHP code architecture. Share to everyone for your reference, as follows:

Write code for more than 6 years, look at the previous architecture, look at the current architecture. There are some deficiencies in the area. Anyway, it's been improving. To tell the truth not too 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 specification, quite a waste of time. Architecture can meet a large part of the requirements, the more people meet the worse performance, this is I do not like the architecture of a major reason. Let's talk about some of the moral aspects of Code architecture.

First, object-oriented, process-oriented supplement

PHP4 is process-oriented, PHP5 and later supports object-oriented.

1, object-oriented program design ideas, for code management, planning more reasonable, better performance and so on.
2, for Process code management, planning is relatively simple, the call way more direct, more clear, efficiency is relatively poor.
Give an 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, a few rooms.
Process-oriented is like a civilian area, if you want to find a family, you need to know, what way, how many number on the line.
If you want to make the high-rise of software park into a house, it will occupy more land. If the park is too large, it is not cheap to find, if the individual consultation room is more convenient. So personally, a good architecture must be oriented towards the object, and the process is supplemented.

Ii. planning of the directory structure

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

Third, single entrance or multi-entry

At the moment I know the PHP framework, or CMS is basically a single entry. Single entrance or multi-entrance, each has a good. One thing to mention is that a single entry must be better than a multi-entry, overriding the URL.

Four, object-oriented hierarchical design

Under normal circumstances, basically three levels is enough, the underlying class, the basic underlying module class, the application class of the combination module. If it is a larger site, the level of division will be more.

Five, the database class to plan well

This is important, and the ideal way is for all SQL executions to go one class. Why this, this is for the long-term plan, in the future to do the MySQL cluster, or the use of memcache such as NoSQL, conversion is also convenient, if SQL everywhere, then depressed.

Class sharing in six or more level two domain names

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

Vii. Use of template plugins

PHP code and HTML code mixed write, I feel bad, especially the website revision, will let you crash. PHP code and HTML are now separated by a lot of templates, for example: Smarty

Eight, JS code planning

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

More interested in PHP related content readers can view the topic: "PHP Basic Grammar Introductory Tutorial", "PHP Object-oriented Programming tutorial" and "PHP Excellent Development Framework Summary"

I hope this article is helpful to you in PHP programming.

Articles you may be interested in:

    • PHP abstract class use points and considerations analysis
    • Summary of Considerations for PHP development
    • How to use PHP callback functions and considerations
    • thinkphp entrance file setup and related considerations analysis
    • Several considerations for using static methods in PHP
    • PHP array Merge Array_merge () function usage considerations
    • php5.3 Notice Notes
    • The method of implementing long connection based on PHP and the problems needing attention
    • Summary of Considerations for PHP-based programming

http://www.bkjia.com/PHPjc/1095690.html www.bkjia.com true http://www.bkjia.com/PHPjc/1095690.html techarticle PHP Code Architecture Eight points of note, PHP architecture eight points This article summarizes the PHP code architecture of the eight points to note. Share to everyone for reference, as follows: Write code for 6 years ...

  • 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.