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 handle other things.
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 the file can be require. of course, you can also write the entry 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.
Single file entry of course is that the website access is always there to access the index. php file, but the content is related to the display is loaded according to the background parameters, such as: 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, you need to create a dedicated routing class to determine the address. action is the operation of this model, such as displaying data, adding data, or displaying the article class, I don't need 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 consider these issues before doing a WEB project.
The following is the file Portal for a template downloaded from the internet. the code is as follows:
- 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. in the PHP file, because PHP templates are open-source, I personally think that some network companies may intentionally call the 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:
-
- 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 also has the idea of the portal. whether it is a single file or multiple files, all use this portal. In short, all the files under the root directory of the website are in this way, the code is as follows:
-
- 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:
-
- $ 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 does not seem very good. it may be because keheng has little experience or is not enough technology. now we have not thought of a better method.