thinkphp6: 开启强制路由(php 8.1.1 / thinkphp v6.0.10LTS )
2022/1/15 11:03:54
本文主要是介绍thinkphp6: 开启强制路由(php 8.1.1 / thinkphp v6.0.10LTS ),对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
一,thinkphp6配置强制路由:
1,修改config/route.php 设置url_route_must一项的值为true 如下:// 是否强制使用路由 //'url_route_must' => false, 'url_route_must' => true,2,查看修改后的效果: 访问:
http://192.168.219.6:8000/article/onemedia?id=1返回: 3,配置路由: 修改route/app.php 增加一行:
Route::get('article/onemedia','article/oneMedia’);如下:
<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- // | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: liu21st <liu21st@gmail.com> // +---------------------------------------------------------------------- use think\facade\Route; Route::get('article/onemedia','article/oneMedia’);4,测试效果: 访问:
http://192.168.219.6:8000/article/onemedia?id=1返回:
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,,配置路由分组:
1,修改route/app.php<?php // +---------------------------------------------------------------------- // | ThinkPHP [ WE CAN DO IT JUST THINK ] // +---------------------------------------------------------------------- // | Copyright (c) 2006~2018 http://thinkphp.cn All rights reserved. // +---------------------------------------------------------------------- // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 ) // +---------------------------------------------------------------------- // | Author: liu21st <liu21st@gmail.com> // +---------------------------------------------------------------------- use think\facade\Route; Route::group('article', function () { Route::get('onemedia', 'article/oneMedia'); Route::get('qr', 'article/qr'); });2,测试效果: 此时qr也可以访问了
三,路由规则不匹配时的处理:
1,在route/app.php中增加一条:Route::miss('article/miss’);2,article.php
<?php declare (strict_types = 1); namespace app\controller; use app\result\Result; class Article extends BaseController { //用来匹配无效的路由 public function miss() { return Result::Error(404,"路由不匹配"); } }3,测试效果: 访问:
http://192.168.219.6:8000/sogou/china返回:
四,查看php和thinkphp的版本:
php:liuhongdi@lhdpc:/data/php/admapi$ php --version PHP 8.1.1 (cli) (built: Dec 20 2021 16:12:16) (NTS) Copyright (c) The PHP Group Zend Engine v4.1.1, Copyright (c) Zend Technologies with Zend OPcache v8.1.1, Copyright (c), by Zend Technologiesthinkphp:
liuhongdi@lhdpc:/var/www/html$ cd /data/php/admapi/ liuhongdi@lhdpc:/data/php/admapi$ php think version v6.0.10LTS
这篇关于thinkphp6: 开启强制路由(php 8.1.1 / thinkphp v6.0.10LTS )的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-19php8的协程和hyperf的协程有什么区别?-icode9专业技术文章分享
- 2024-12-19php8 的fiber是什么?-icode9专业技术文章分享
- 2024-12-05怎么在php8,1 里面开启 debug?-icode9专业技术文章分享
- 2024-12-05怎么在php8,1 里面开启 debug?-icode9专业技术文章分享
- 2024-11-29使用PHP 将ETH账户的资产汇集到一个账户
- 2024-11-23怎么实现安卓+php 热更新方案?-icode9专业技术文章分享
- 2024-11-22PHP 中怎么实现判断多个值是否为空、null 或者为 false?-icode9专业技术文章分享
- 2024-11-11开源 PHP 商城项目 CRMEB 二次开发和部署教程
- 2024-11-09怎么使用php在kaufland平台刊登商品?-icode9专业技术文章分享
- 2024-11-05PHP的抽象类和接口是什么,有什么区别-icode9专业技术文章分享