Home >Backend Development >PHP Tutorial >Detailed explanation of file entry examples of MVC framework in PHP_PHP tutorial
This article introduces new knowledge about PHP. Friends who need to know more about the file entry usage of the MVC framework in PHP can refer to this article.
How to write the file entry of MVC is completely based on the programmer's engine design and the programmer's preferences, but our ultimate goal is to introduce the engine to handle other transactions through simple code, like Just like when we want to drive a car, we first need to ignite it before the engine can start. Before writing the entry, we need to consider several aspects, such as the URL parsing method, which user parameters or systems need to be brought in, and where the user parameters need to be changed, we need to use a file to introduce them. The file can be xml or PHP. , or other methods that come to mind, but Keheng here uses the array form in PHP to introduce it. This form looks like a write cache. It reads the data from the database and then generates a PHP file, and then requires this file. . Of course, we can also write the entry in the process of writing the engine, as long as it can achieve our purpose.
As far as the file entries we usually see are concerned, file entries are generally divided into single file entries and multi-file entries. Of course, there may be other file entries that we have not seen before.
Single file entry, of course, means that the file index.php is always accessed when accessing the website, but the content displayed inside is loaded according to the background parameters,
For example: http://www.XXXX.com/index.php?Conttoller=index&action=show&id=1
The Controller here is the page we need to display. By getting the value of the Controller to determine which model our MVC is loading and which view is displayed, it is generally necessary to establish a dedicated routing class to determine the address. Action refers to the operation of this model, such as displaying data, adding data, or displaying articles. As for the role of ID, it goes without saying here.
Multi-file entry, of course, means that in addition to the index.php file name, there are other file accesses in the website, such as index.php, about.php, etc. under the same website.
But there is another URL method http://localhost/control/ index / action/1. This method does not specify which file in this directory to access. The default is of course index.php or index. html, I personally think that this method is more troublesome in terms of program production and maintenance, so it is rare to see URLs in this form now. I have read articles about SEO before, and it seems that the entrance is this type of SEO optimization. Not very good (keheng's humble opinion). In fact, we can usually observe whether it is not very good. For example, if we enter a keyword casually in Baidu, there will be almost no similar addresses found in the first few pages. In SEO optimization, it is advisable to keep the hierarchical structure of the address URL within three levels. Of course we must consider these issues before we start a WEB project.
The following is the file entry of a template downloaded from the Internet:
The code is as follows | Copy code | ||||
define('VERSION', 'v2.1 Released'); define('UPDATETIME', '20120323'); define('APP_NAME', 'myphp'); define('APP_PATH', './myphp/'); define('APP_LANG', true); define('APP_DEBUG',false); define('THINK_PATH','./Core/'); require(THINK_PATH.'/Core.php');
|
代码如下 | 复制代码 |
|
The code is as follows | Copy code |
require_once './include/common.inc.php'; $views->display('index.html'); ?> |
After loading the engine file, tell the $views class which view file to display. This is indeed much more intuitive, but I personally don’t like this method. Although if you modify the file template and modify it directly in the corresponding file, it feels like It's not easy to control, and $views is not closed at the end, occupying memory.
After reading some other people’s entrances, Keheng also had ideas for his own entrance. Whether it is a single file or multiple files, all use this entry. In short, the contents of all the files in the root directory of the website are this
The code is as follows
|
Copy code
|
||||
require 'command/config.php'; require 'command/app.php'; app::run($config); ?>
| Actually, my object model is set in config.php
The code is as follows |