ThinkPHP5 API路由注册和其地址访问

1、资源控制器

使用cmd命令,进入到项目的根目录,使用完整的命名空间生成对应的文件

php think make:controller app\api\controller\User2


2、config.php配置文件

    // 是否开启路由
    'url_route_on'           => true,
    // 路由使用完整匹配
    'route_complete_match'   => false,
    // 路由配置文件(支持配置多个)

    'route_config_file'      => ['route','apiRoute'], // 对应application下的route.php 或者自己新建的 apiRoute.php

**route.php或者apiRoute.php文件中配置接口信息:

Route::get('index/info','api/index/getInfo');// 访问方式 http://www.xx.com/index/info

Route::get('index/getInfo','api/index/getInfo');// 访问方式 http://www.xx.com/index/getInfo

//Route::rule(['index/getInfo'=>'api/index/getInfo'],'','GET');

猜你喜欢

转载自blog.csdn.net/a898712940/article/details/78842509