关于Thinkphp5.0.24 某cmf路由定义问题

我想用如下方式定义API路由

Route::group('api', function () {
    Route::any('petclass', "/api/pet/Petclass", [], ['id' => '\d+']);
}, ['method' => 'any', 'ext' => 'html']);

文件目录:

关于Thinkphp5.0.24 某cmf路由定义问题

期望以 host/api/petclass 的形式访问资源 ,但试了很多都是404,考虑是不支持这样 。。

我的目的是想用分组路由的形式 将所有api放到同一个分组里 ,大佬们 有啥方案吗?

@李山河
你看我吊吗啊
你看我吊吗啊
最佳答案

知道正确的怎么写了 ,但是不知道错误的是哪里错了。。

/*错误示范*/
Route::group('api1', function () {
    Route::get(':id', 'api/pet.petclass/index');//,[],['id'=>'\d+']
}, ['method' => 'get', 'ext' => 'html']);
//正确示范
Route::group('pet', [
    "class" => "api/pet.petclass/index"
]);
2年前 评论
讨论数量: 1
你看我吊吗啊

知道正确的怎么写了 ,但是不知道错误的是哪里错了。。

/*错误示范*/
Route::group('api1', function () {
    Route::get(':id', 'api/pet.petclass/index');//,[],['id'=>'\d+']
}, ['method' => 'get', 'ext' => 'html']);
//正确示范
Route::group('pet', [
    "class" => "api/pet.petclass/index"
]);
2年前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!