Home > Article > PHP Framework > What should I do if thinkphp5 does not allow the .php suffix?
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+']);
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!