ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 开启路由 1. 首先要先在配置文件中开启路由功能:'ROUTE_ON'=>true, 2. 在配置文件中定义路由规则的分隔符:'ROUTE_DELIMIT'=>'-', ## 规则定义: **1. 在入口文件中定义路由规则** <?php define('IN',str_replace('\\','/',dirname(__FILE__)) . '/'); define('APP_PATH','home'); define('DEBUG',1); require('../core/core.php'); /*在此位置定义路由规则*/ route(['u'=>['user','index','userid']]); route(['my'=>['index','my','id']]); route(['t'=>['user','info','uid','name','age','sex']]); /*定义路由规则结束*/ \z\z::start(); **2. 单独配置路由规则文件** 需要在 应用目录/common/ 目录下增加 route.php 文件 <?php return array( ['u'=>['user','index','userid']], ['my'=>['index','my','id']], ['t'=>['user','info','uid','name','age','sex']] ); >[danger]**规则解释** http://xxx.com/index.php/u-12 将被路由到 http://xxx.com/index.php?c=user&a=index&userid=12 http://xxx.com/index.php/my-2 将被路由到 http://xxx.com/index.php?c=index&a=my&id=2 http://xxx.com/index.php/t-1-2-3-4 将被路由到 http://xxx.com/index.php?c=user&a=info&uid=1&name=2&age=3&sex=4 url解析先按照规则中的键名(u , my , t)匹配 键值数组中的**前两个值**被依次解析为 **控制器名** 和 **操作名** 剩余的值被解析为GET参数名 url中的 -1-2-3-4 将 **按顺序** 对应 GET参数值