下面我看到了关于子域的文档。
我的控制器文件夹结构是:
所有路由都使用控制器文件中的注释来定义。
例:
#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/scripes.yaml文件中:
#config/routes.yaml
main:
host: "localhost"
resource: ../src/Controller/Main
type: annotation
admin:
host: "admin.localhost"
resource: ../src/Controller/Admin
type: annotation我想要的是:
bin/控制台服务器:启动
- access to [http://admin.localhost/](http://admin.localhost/) => homepage method in src/Controller/Admin/HomeController
- access to [http://localhost/](http://localhost/) => homepage method in src/Controller/Main/HomeController
但只有http://admin.localhost/ works和http://localhost/ get 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: annotationhttp://localhost/ works和http://admin.localhost/ get 404带有欢迎消息
发布于 2019-02-04 19:12:57
我使用此命令行进行调试。
php /console调试:路由器
由于同名,只有最后一个读到:
@Route("/", name="home")我只是把行政名称改为
@Route("/", name="admin-home")现在起作用了
https://stackoverflow.com/questions/54521427
复制相似问题