【发布时间】:2019-06-28 12:08:06
【问题描述】:
我在doc 之后阅读了有关子域的信息。
我的控制器文件夹结构是:
- src/控制器/管理员
- src/Controller/Main
所有路由都在控制器文件中用注释定义。
例如:
#src/Controller/Admin/HomeController.php
class HomeController extends AbstractController
{
/**
* @Route("/", name="home")
* @return \Symfony\Component\HttpFoundation\Response
*/
public function homepage(){...}
}
#src/Controller/Main/HomeController.php
class HomeController extends AbstractController
{
/**
* @Route("/", name="home")
* @return \Symfony\Component\HttpFoundation\Response
*/
public function homepage(){...}
}
所以我在 config/routes.yaml 文件中添加了以下配置:
#config/routes.yaml
main:
host: "localhost"
resource: ../src/Controller/Main
type: annotation
admin:
host: "admin.localhost"
resource: ../src/Controller/Admin
type: annotation
我想要的是:
- 我使用以下命令运行服务器:
bin/控制台服务器:启动
-
结果除外:
访问http://admin.localhost/ => src/Controller/Admin/HomeController中的主页方法
访问http://localhost/ => src/Controller/Main/HomeController中的主页方法
但只有 http://admin.localhost/ 有效,http://localhost/ 收到 404 并显示以下消息:“欢迎使用 Symfony 4.2.2”
如果我在 yaml 文件中交换订单:
#config/routes.yaml
admin:
host: "admin.localhost"
resource: ../src/Controller/Admin
type: annotation
main:
host: "localhost"
resource: ../src/Controller/Main
type: annotation
http://localhost/ 有效,http://admin.localhost/ 收到带有欢迎信息的 404
如何使用built-in web server 运行subdomain。
【问题讨论】:
-
您如何将
project_demo.test指向内置服务器?您对子域也这样做了吗? -
我只是运行 bin/console server:start 并为两者(admin.localhost 和 localhost)使用相同
标签: symfony