This article introduces the new php knowledge about the file entry usage of the MVC Framework in PHP. For more information, see this article.
How to write the MVC file entry is completely based on the programmer's engine design and the programmer's preferences. However, our ultimate goal is to use simple code to introduce the engine to process other transactions, just as we need to drive, we need to ignition first before the engine can start. Before writing an entry, we need to consider several aspects: URL resolution, which user parameters or systems need to be brought in, and where user parameters need to be changed, we need to use a Unified File for introduction, files can be xml, PHP, or other methods, but keheng uses arrays in php to introduce them. This format seems to be the form of cache writing, the data read from the database is regenerated into a PHP file, and then require this file. Of course, you can also write the entry point in the write engine process, as long as it can achieve our goal.
As we usually see in the file portal, the file portal is generally divided into single file portal and multi-file portal, of course, there may be other file portals not seen.
A single file portal means that the website always accesses the index. php file, but the content displayed in the portal is loaded according to the background parameters,
For example: http://www.XXXX.com/index.php? Conttoller = index & action = show & id = 1
Here, Conttoller is the page we need to display. by obtaining the Conttoller value, we can determine which model is loaded by MVC and which view is displayed, generally, a dedicated routing class is required to judge the address. Action is the operation of this model, such as displaying data, adding data, or displaying the document class. It is not necessary to mention the role of ID.
Multi-file portal means that the website has access to other files except the index. php file name. For example, index. php, about. php ........... .
However, there is another URL method, http: // localhost/control/index/action/1, which does not specify which file is stored in this directory. Generally, index.php#index.html is used. I personally think this method is troublesome for program creation or maintenance, so now we rarely see this form of URL. I have read SEO articles before, and it seems that the entrance is of this type and SEO optimization is not very good (keheng's personal opinion ). In fact, it is not very good. We can usually observe it. For example, if we enter a keyword under Baidu, we cannot find similar addresses on the first few pages. In SEO optimization, it is recommended that the hierarchical structure of the url be kept within the three layers. We must take these issues into account before doing a WEB project.
The following is the file portal for a template downloaded from the Internet:
The Code is as follows: |
Copy code |
Define ('upload _ path', './Uploads /'); Define ('version', 'v2. 1 released '); Define ('updatetime', '123 '); 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 '); |
Its Core is THINK. The entry specifies the program version, update date, and so on. The actual processing file is in the Core. php file. Since PHP templates are open-source, I personally think that some network companies may intentionally call PHP code at multiple levels to prevent them from completely figuring out their products, to confuse the programmers who want to learn their code ideas, let the programmers follow suit, in fact, this is the case, it may be caused by lack of experience.
The Code is as follows: |
Copy code |
<? Php Require_once './include/common. inc. php '; $ Views-> display('index.html '); ?> |
After the engine file is loaded, it is really intuitive to tell the $ views class which View File to display, but I personally don't like this method, although it is difficult to modify the file template directly in the corresponding file, and $ views does not close at last, it occupies the memory.
After reading some other people's portals, keheng has his own idea of portal. Whether it is a single file or multiple files, all use this portal. In short, all files under the root directory of the website are in this
The Code is as follows: |
Copy code |
<? Php Require 'COMMAND/config. php '; Require 'COMMAND/app. php '; App: run ($ config ); ?> |
In fact, my image model is set in config. php.
The Code is as follows: |
Copy code |
<? Php $ Config ['templates'] = array (// The name must be converted to lowercase. 'Keheng' => array ('keheng. php', 0 ), 'Index' => array ('index. php', 0 ), ); ?> |
The analysis address calls the corresponding view, so that I can use a file to set the model and view. When using the address, I can use require 'COMMAND/config. php '; load this array.
Some people may think that this method is not very good. It may be because keheng has little experience or is not enough technology. Now, I have not thought of a better method.