在route.php中
return [
'hello/:id' => 'index/Hello/index',
];
Hello.php中
<?php
namespace app\index\controller;
use think\Controller;
class Hello extends Controller
{
public function index()
{
if (request()->isGet()) echo "当前为 GET 请求";
if (request()->isPost()) echo "当前为 POST 请求";
}
}
TP5解决了TP3中路由不能反转的问题,使用 url助手函数生成URL的时候用 url('index/Hello/index','id=1') 生成的地址 为 /hello/1