Home PHP Framework ThinkPHP What should I do if thinkphp5 does not allow the .php suffix?

What should I do if thinkphp5 does not allow the .php suffix?

Apr 11, 2023 pm 03:08 PM

Recently, many ThinkPHP5 developers have reported that the system no longer allows the use of the .php suffix when setting up URL routing. This change has triggered heated discussions among netizens.

ThinkPHP is a mature and widely used PHP framework in China. Its simplicity, ease of use, rich functions, and excellent performance make it deeply loved by developers. However, in ThinkPHP 5.1.0 version, a major change is gradually getting into the eyes of developers: the system no longer allows the use of the .php suffix.

In fact, in the update log of version 5.1.0, the official has already explained this change. Specifically, when we set up URL routing, if the routing rule contains the .php suffix, the system will give the following prompt: The PHP suffix is ​​no longer supported.

This change has confused some developers who are accustomed to using the .php suffix. Why does ThinkPHP5 no longer support the .php suffix? The official explanation is that this is because the suffix of PHP, as a scripting language, does not match the structure of the URL access prefix, so it is not conducive to system retrieval and parsing. As more and more developers begin to use new API development methods such as RESTful API, it has become a trend to express the URL structure more simply and clearly. Therefore, support for the .php suffix has been canceled in version 5.1.0. .

So, how to set up URL routing in ThinkPHP5? Basically, we can still use PHP closures and other methods for routing settings. For example, we can set the following URL routing rules:

Route::rule('news/:id','index/news/read',['method'=>'get'],'',['id'=>'\d+']);
Copy after login

With this setting, when the user accesses the URL address /news/123, the system will automatically call the news method in the index controller, and the id in the parameter The value will be set to 123. Because there are no .php suffix constraints and there is no need to set Rewrite rules, developers only need to write the above code and then enter the corresponding URL address in the browser to perfectly display the relevant pages.

In short, although the removal of support for the .php suffix has disappointed old technology enthusiasts to a certain extent, judging from the overall performance of ThinkPHP5.1.0 version, this change may be more conducive to the speed of the system. Retrieval and analysis are also more in line with the trend of modern API development. Therefore, in order to better keep pace with the times and maintain the high performance and security of the system, we should actively adapt and apply this change during the development process.

The above is the detailed content of What should I do if thinkphp5 does not allow the .php suffix?. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)