PHP Single entry overview and pros and cons analysis

Source: Internet
Author: User
Tags zend framework

Single Entry Overview

A single-entry application means that a file is used to process all HTTP requests, such as a list page or an article page, to access the index.php file from the browser, which is a single entry for the application.

For example, we all have to go to the WC, all the boys into a door, the girls into a door, these two doors is the WC two entrance. And now go to a park inside the WC, outside there is a door, regardless of men and women from the most outside the door entered, pay the money before entering the men's toilet door or the bathroom door, and the most outside door is the single entrance of the WC.

Implementation Method

Very simply, a specific parameter can be accessed on the index.php time limit. For example index.php?action=list is to access the list page, while Index.php?action=single accesses the article page.

Implementation code:
$action =$_get[' action ']== '? ' Index ': $_get[' action '];//takes the action parameter from the URL and sets a default ' index ' as the parameter if no action argument is supplied
Include (' files/'. $action. php ');//The different code files are called according to the $action parameter, thus satisfying the different functions corresponding to a single entry implementation.

benefits of a single portal application

All HTTP requests for a single-entry application are received and forwarded to the function code via index.php, so a lot of actual work can be done in index.php.

Since all HTTP requests are received by index.php, centralized security checks can be performed, and if not a single entry, developers must remember to add security check code at the beginning of each file
(Of course, the security check can be written to another file, only the include is required.) )

Similar to security checks. In the portal, we can also make necessary checks and special character filtering for URL parameters and post, log logs, access statistics, and so on, which can be centrally handled tasks.
As you can see, the work has been focused on index.php, which can ease the difficulty of maintaining other functional code.

Disadvantages of single-entry applications

There are two sides to everything, and a single portal application is no exception. Because all HTTP requests are for index.php, the URL of the program does not look so beautiful, especially for search engines.
To solve this problem, you can use URL rewriting, PathInfo, and so on, but you can not use a single entry in the foreground page, but to maintain multiple file portals. or mix them.

For a single portal (a project that accesses a site must first pass a file, typically index.php to implement other functions), the program:
The most common URLs are: Http://www.nostop.org/index.php?controller=posts&action=index

To tell the truth such a URL is very difficult to see, the most important is that the search engine does not recognize it as the normal URL, which is very scary. How to achieve a good-looking and with the search engine can climb the URL of the pro.
Look at this url:http://www.nostop.org/index.php/posts/index/.

Very novel URL creative, which is also a pseudo-static experience in the process of cakephp framework, this URL relative to the URL: Easy to remember, beautiful, the main thing is that the search engine does not recognize it as Dad, at least not to the blacklist.

Explain the above URL, "posts": it is generally referred to as the controller, which determines which processing file to load; "index": it is generally called an action, which determines what to do. So/posts/index/as the name implies is posts homepage. If you need to pass parameters later, you can add them directly behind the action.

As in the following url:http://www.nostop.org/index.php/posts/category/1/. Lists all content under the category ID of posts 1.

Some of the frameworks in PHP, Zend framework,thinkphp,fleaphp,qeephp, and cakephp are all single-entry modes, they all use a unified portal, can be based on different needs, the front entrance to the background entrance or other access to the operation of the entrance, The advantages of this design pattern are obvious, for example. Permission control, URL rewriting, combines MVC with a clear directory structure. These are the convenience of a single-entry model, which, of course, raises questions about the efficiency of implementation.

PHP Single entry overview and pros and cons analysis (RPM)

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.