首页 > 解决方案 > Symfony 路由配置控制中的 `type:` 配置是什么?

问题描述

type:Symfony 路由文件中的配置控制什么?它的有效值是多少?

我在任何地方都找不到明确记录的这个配置字段。它在 Symfony 的路由文档中被间接引用。

app_directory:
    resource: '../legacy/routing/'
    type:     directory

并且似乎与加载其他路线有关。但是,它的行为(或其所有允许的值)似乎没有在任何地方明确定义。我可以猜测它以某种方式告诉 Symfony如何加载外部路由,但我很想知道

  1. 我的猜测正确吗?
  2. directory是否有除or以外的有效值annotation
  3. 这是否正式记录在任何地方?
  4. Symfony 内部是否有一个地方可以作为我自己开始寻找这些答案的好地方?

标签: phpsymfonyrouting

解决方案


您可以在 Symfony文档中找到该类型的工作原理,请参见下面的代码。它控制是否应从该(捆绑)目录中找到的 PHP 注释或 YAML 或 XML 文件加载路由。

app_file:
    # loads routes from the given routing file stored in some bundle
    resource: '@AcmeOtherBundle/Resources/config/routing.yaml'

app_annotations:
    # loads routes from the PHP annotations of the controllers found in that directory
    resource: '../src/Controller/'
    type:     annotation

app_directory:
    # loads routes from the YAML or XML files found in that directory
    resource: '../legacy/routing/'
    type:     directory

app_bundle:
    # loads routes from the YAML or XML files found in some bundle directory
    resource: '@AppBundle/Resources/config/routing/public/'
    type:     directory

推荐阅读