我正在使用symfony和API平台设置项目,如果我在控制台中运行路由调试器,则可以看到我的新路由:
--------------------------- -------- -------- ------ -------------------------------------
Name Method Scheme Host Path
--------------------------- -------- -------- ------ -------------------------------------
_preview_error ANY ANY ANY /_error/{code}.{_format}
api_entrypoint ANY ANY ANY /api/{index}.{_format}
api_doc ANY ANY ANY /api/docs.{_format}
api_jsonld_context ANY ANY ANY /api/contexts/{shortName}.{_format}
api_users_get_collection GET ANY ANY /api/users.{_format}
api_users_post_collection POST ANY ANY /api/users.{_format}
api_users_get_item GET ANY ANY /api/users/{id}.{_format}
api_users_delete_item DELETE ANY ANY /api/users/{id}.{_format}
api_users_put_item PUT ANY ANY /api/users/{id}.{_format}
api_users_patch_item PATCH ANY ANY /api/users/{id}.{_format}
--------------------------- -------- -------- ------ -------------------------------------
但是,我在浏览器中看不到它们。如果我转到http://localhost,则可以看到symsony4主页;如果我转到http://localhost/api,则将看到“未找到错误”。
这是调试api_entrypoint路由时的输出
+--------------+------------------------------------------------------------+
| Property | Value
|
+--------------+------------------------------------------------------------+
| Route Name | api_entrypoint
|
| Path | /api/{index}.{_format}
|
| Path Regex | #^/api(?:/(?P<index>index)(?:\.(?P<_format>[^/]++))?)?$#sD |
| Host | ANY
|
| Host Regex |
|
| Scheme | ANY
|
| Method | ANY
|
| Requirements | index: index
|
| Class | Symfony\Component\Routing\Route
|
| Defaults | _api_respond: true
|
| | _controller: api_platform.action.entrypoint
|
| | _format:
|
| | index: index
|
| Options | compiler_class: Symfony\Component\Routing\RouteCompiler |
+--------------+------------------------------------------------------------+