【发布时间】:2019-06-06 09:59:49
【问题描述】:
我正在尝试使用 symfony 4 实现 REST API。我的问题是我的方法 GET 和 POST 无法到达我的路由。每次我尝试,都会收到 404 错误。
但是当我尝试在 symfony 上获取路线时,我有:
Name Method Scheme Host Path
app_statistics_poststatistics POST ANY ANY /api/stat
app_statistics_getstatistics GET ANY ANY /api/stat/{statId}
所以我的路线确实存在,但我无法到达。
我正在使用 WAMP 开发 Windows 环境以在本地工作。
我已经在 2 个 Windows 环境和一个带有 LAMP 的 Linux 环境上尝试了我的 api。总是收到 404 Not Found。
教程的作者告诉我,我的 api 正在他的计算机上运行,但我没有关于他的环境的更多信息。所以,我认为问题出在我的虚拟主机的配置上。
这是我的虚拟主机:
<VirtualHost *:80>
ServerName statroche.fr
ServerAlias www.statroche.fr
DocumentRoot "D:/other/symfony/testRoche/public"
<Directory "D:/other/symfony/testRoche/public">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Require local
</Directory>
</VirtualHost>
重要提示:我的公共文件夹中没有任何内容,因为我不想要任何页面,只需要 API,我还需要在 DocumentRoot 和 Directory 中输入“公共”吗?。
我想访问我的 API,然后对于 GET 方法,例如,返回一个 json。实际上,我可以到达我的项目的/,但无法到达其他路线。
【问题讨论】:
-
那么,如果您在
public文件夹中没有index.php,您就没有Symfony 开始运行的入口点——您在访问/时看到通常的欢迎页面吗? -
不,我看不到经典的欢迎页面,但我可以在我的虚拟主机中使用
+Indexes访问/
标签: symfony wamp virtualhost symfony4