Home>Article>PHP Framework> What is the use of route routing in thinkphp

What is the use of route routing in thinkphp

WBOY
WBOY Original
2022-02-18 15:29:06 1977browse

In thinkphp, the function of route routing is to simplify the URL access address and make correct parsing according to the defined routing type. The purpose of routing is to simplify the path and define some rules while simplifying the path. .

What is the use of route routing in thinkphp

The operating environment of this article: Windows 10 system, ThinkPHP version 5, Dell G3 computer.

What is the use of route routing in thinkphp

The network access address has always been mapped. Initially, it was like this, host name (computer name) =>ip address (such as LAN 192.168.1.1 )

The routing definition is to hide the real url address and use the access address to access the application (website or OA or something). It is usually defined like this: 'Access address' => 'Real address', which means It creates a mapping relationship, such as using "1" to represent going to your home, and using "0" to represent going to your colleague's home, which is the same principle. The routing rules are determined by TP. For example, the access rules of TP are: root directory/module/controller/method. We only need to define the mapping relationship, such as 'reg'=>'index/user/reg', then I only need to enter: "domain name/reg" in the browser to access "index module/user controller/reg Method" this address.

Because normally the url paths we have not processed are composed of modules/controllers/methods/parameters. If not "covered", some people will see the internal structure clearly. What will be done? When there is a certain amount of beauty in terms of aesthetics

, the URL request can be elegantly mapped to the operation method you want to perform. thinkphp's routing can make your URL address more concise and elegant

1. What is Route (routing)?

The official document defines it like this => The function of routing is to simplify URL access addresses and make correct parsing based on the defined routing type.

Manual explanation: When we usually access our ThinkPHP project according to our habits, the regular url should be written like this, (local example) http://localhost/project name/public/index. php/module name/controller name/method name

After entering a string of URLs, you will feel very desperate, (whispering) => "I just want to test a small interface that makes me type so long. A string of addresses, the address is too long to remember...". At this time, we can use routing to simplify his address, and define some rules while shortening the address.

2. Why use routing?

Some people may blurt out: To simplify the path. Of course, this is one reason, but the reason is not that simple.

Simplifying the path is a big reason, because I thought the path was too long at first and ran over to open the route. But later in the process of using it, I found that the role of Route is not limited to simplifying the path. .

We can enable the forced use of routing, so that everyone can only come in from the route I defined. This has an advantage. If you write some scripts in some controllers that you do not want to give users access to, you can fully enable them. If routing is forced to be used, users cannot access these scripts. Otherwise, if users access these scripts and the scripts sometimes modify the database, it will be more dangerous.

Also, we can define whether the entry from this path is a get operation or a post operation, so that there will be no situation like before. A controller method can be accessed from get or post. Access is very messy. Of course, some people will say that it’s no big deal if both get and post can be accessed. In fact, distinguishing these methods is more helpful for embodying the idea of Restful API.

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What is the use of route routing in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn