According to the idea of page display and logical separation, the browser requests a logical file, while the displayed file is only used for loading the logical file.
This type of display file contains HTML, PHP, and other mixed files. It is characteristic that PHP code is only used to output data, not to process data. We regard this type of file as a template file.
Template files may leak PHP business logic and must be prevented from being directly accessed by browsers.
There are two methods to process template files.
The first method is to put the template file into a separate directory that is not accessed by the browser, and the directory cannot be accessed through the browser.
Principle: The directory permission is set through. htaccess to hide the directory.
Even if you directly access the template file through a browser, you cannot access the template file. The error 403 forbidden is displayed.
Note: To ensure that. htaceess can be executed, you must rely on the Apache configuration file to allow the use of the distributed configuration file. htaccess
Another method requires higher permissions. Generally, the server is an independent host and the template file is placed somewhere outside the root directory.
In this way, users cannot access it, because the access via a browser is always in the root directory.
Principle: to load a template file in a logical file, you can use require to load the template file to the PHP logic runtime environment and load it together with the logical file to the memory.
The user accesses the template file and uses the URL to access the template file.
So far, two layers of separation of display and logic have been completed.
However, if there are more and more functions and more code and pages, we will find that the logic of a page is similar to that of another or more pages, resulting in redundancy. Therefore, we need to separate the logical files again, this idea is MVC.
1. Data Processing Layer (model layer)
2. Function scheduling layer (Controller)
3. Page Result Display (view layer, that is, template file)
Note:
① The browser requests the function scheduling page, that is, the control layer page, and then the Controller calls the Data Processing Layer Model and PAGE result display layer view;
② There is no interaction between the model layer and the view layer;
③ The model layer and view layer can only be called by the Controller.
Football Match-4