Create a PHP program with flexible structure

Source: Internet
Author: User
I wanted to write this article for a long time, but I never had time to finish it. I don't mean to tell you how to do it. I look forward to reading this article as an introduction to discuss with you how to build an effective and mobile network utilization program. After

I wanted to write this article for a long time, but I never had time to finish it. I don't mean to tell you how to do it. I look forward to reading this article as an introduction to discuss with you how to build an effective and mobile network utilization program.

After 2-3 years of network application development work, my development experience has become more lively. when I go back to the fire, I can't trust the code I wrote for Geocrawler. Due to GPL, the source code in PHPBuilder is also uneven.

Recently, as an experienced PHP developer, I have been helping to write SourceForge. I think this shows a category of the ultimate achievement. Good code should be divided into multiple parts, suitable library and function call, clear database structure, each part of the site is relatively independent from other parts.

However, this is still not the best. If I can redo it, I will focus more on the differences between the HTML layer and the data layer, through the object and the function library to achieve this.

Exquisite graphics

I know managers love to describe them with exquisite graphics and charts, which will give us the best impression. With this idea of hiding behind a structure, you can separate your logic and appearance, which means that any complicated program can be expressed by 'api/Data Access layer.

Rather than placing security detection and updated sentences on the HTML layer, you should put them in your API layer as a whole. The HTML layer only contains simple function calls and returned arrays, objects, custom items, and aggregation of some database retrieval results.

If you do this, the top layer will be very small and you can easily create and protect it.

In the following example, only some functions in the API layer can be directly called in this HTML interface, and some HTML tool libraries (which can be a pop-up box by nature ), and some database control methods called from the database abstraction layer (you do not need to bind a special database ).

Basic

The most basic aspects of the mobile PHP program structure are as follows:


Database independence
Interface independence
Portability
Object-oriented or at least composed of function libraries

What else?
Of course there are some other things, but I think they are too big. maybe you can point them out by yourself.


Let's talk about each of them in detail.

1. Database independence

You never know where your site will run. of course, when you create it, you may expect it to grow bigger and have high traffic. So you don't want to tie yourself to MS Access or any other lightweight database system. Although you cannot immediately plug in different database systems, you may easily switch between them. You have some different options to abstract your database calls. One strange way in PHP is that you have to write different code for each different database system, because the visiting functions for each different database in PHP are different. To avoid this, you can apply an abstract database access layer, just like PHPLib, the next version of PEAR, and what we described in SourceForge.

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.