ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## 生成路由 使用`siteUrl`函数生成路由(该函数写在`application\Common.php`文件中) ``` /** * 生成url * @param string $url 路由地址,类似于tp5的url()函数的第一个参数 如:index/index/hello * @param string $vars 路由参数 * @param string $weDoor 微擎入口 web-Web端入口,app-App端入口 * @return array|string */ siteUrl($url = '', $vars = '', $weDoor = '') ``` 使用用过`thinkphp5`的`url`函数的同学应该清楚,前两个参数和`url`函数类似, 而`$weDoor `这个参数,不传则默认当前入口,不清楚可以[查看微擎手册 ](http://s.w7.cc/index.php?c=wiki&do=view&id=1&list=13) ## 路由参数 如链接:`http://we7demo.com/app/index.php?m=tp5_chen&c=entry&a=site&i=6&do=index&tp_c=index&tp_a=index` 在`tp5_chen\index.php`文件中有以下代码 ~~~ //微擎模块 $m = $_GPC['m']; //设置常量 define('MODULE_NAME',$m); //tp模块 $tpM = $_GPC['do'] ? $_GPC['do']:'index'; //tp控制器 $tpC = isset($_GPC['tp_c'])? $_GPC['tp_c']:'index'; $_GPC['tp_c'] = $tpC = strtolower(trim(preg_replace("/[A-Z]/", "_\\0", $tpC), "_")); //tp方法 $_GPC['tp_a'] = $tpA = isset($_GPC['tp_a'])? trim($_GPC['tp_a']):'index'; // 加载基础文件 require __DIR__ . '/thinkphp/base.php'; // 执行应用并响应 Container::get('app')->path(__DIR__.'/application/')->bind($tpM."/".$tpC."/".$tpA)->run()->send(); ~~~ `do` 参数相当于`tp`的模块参数 `tp_c` 参数相当于`tp `的控制器参数 `tp_a` 参数相当于`tp` 的方法参数 对于这个`Container`类不了解的可以看tp5.1手册和代码[https://www.kancloud.cn/manual/thinkphp5\_1/353956](https://www.kancloud.cn/manual/thinkphp5_1/353956)