如何加载在 dev 子目录中声明的路由? (在开发环境中)
How to load routes declared in dev subdirectory? (in dev environment)
我正在用 Flex 测试 Symfony。我有一个非常小的应用程序,运行良好(幸运数字生成器)。我想通过 Flex 添加 web_profiler。
我启动这个命令:
composer require web_profiler --dev
一切正常,缓存已成功预热。但是当我查看我的主页时,出现错误:“_wdt”路由不存在。
我检查了新的 config/routes/dev/web_profiler.yaml
文件。它是由 Flex 创建的。它包含:
web_profiler_wdt:
resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
prefix: /_wdt
web_profiler_profiler:
resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
prefix: /_profiler
好像还不错。我复制此代码并将其附加到我的 config/routes.yaml
。错误消失。我了解到 config/routes/dev
子目录中的 yaml 文件未加载。
为什么我在 /config/routes/dev subdirectory
中的文件没有加载?我忘记加载我的开发配置文件的哪一步?
这是我的 .env
文件:
# This file is a "template" of which env vars needs to be defined in your configuration or in an .env file
# Set variables here that may be different on each deployment target of the app, e.g. development, staging, production.
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
###> symfony/framework-bundle ###
APP_ENV=dev
APP_DEBUG=1
APP_SECRET=80b8077a9ccaaf2b5dd3427b512bae42
###< symfony/framework-bundle ###
这是我的 config/routes.yaml
文件
index:
path: /
defaults: { _controller: 'App\Controller\GeneratorController::numberAction' }
# Depends on sensio/framework-extra-bundle, doctrine/annotations, and doctrine/cache
# install with composer req sensio/framework-extra-bundle annot
controllers:
resource: ../src/Controller/
type: annotation
这是配置子目录的屏幕截图。我认为我尊重标准:
缓存已成功预热,但还不够。要工作,我也必须清除缓存。
在我的 composer.json 中,我为 post 更新命令添加了一行:
"scripts": {
"auto-scripts": {
"assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd",
"security:check": "symfony-cmd",
"cache:clear --no-warmup": "symfony-cmd",
"cache:warmup": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
添加的行是这一行:"cache:clear --no-warmup": "symfony-cmd"
安装应用程序时不需要此行,但在更新期间需要。
我正在用 Flex 测试 Symfony。我有一个非常小的应用程序,运行良好(幸运数字生成器)。我想通过 Flex 添加 web_profiler。
我启动这个命令:
composer require web_profiler --dev
一切正常,缓存已成功预热。但是当我查看我的主页时,出现错误:“_wdt”路由不存在。
我检查了新的 config/routes/dev/web_profiler.yaml
文件。它是由 Flex 创建的。它包含:
web_profiler_wdt:
resource: '@WebProfilerBundle/Resources/config/routing/wdt.xml'
prefix: /_wdt
web_profiler_profiler:
resource: '@WebProfilerBundle/Resources/config/routing/profiler.xml'
prefix: /_profiler
好像还不错。我复制此代码并将其附加到我的 config/routes.yaml
。错误消失。我了解到 config/routes/dev
子目录中的 yaml 文件未加载。
为什么我在 /config/routes/dev subdirectory
中的文件没有加载?我忘记加载我的开发配置文件的哪一步?
这是我的 .env
文件:
# This file is a "template" of which env vars needs to be defined in your configuration or in an .env file
# Set variables here that may be different on each deployment target of the app, e.g. development, staging, production.
# https://symfony.com/doc/current/best_practices/configuration.html#infrastructure-related-configuration
###> symfony/framework-bundle ###
APP_ENV=dev
APP_DEBUG=1
APP_SECRET=80b8077a9ccaaf2b5dd3427b512bae42
###< symfony/framework-bundle ###
这是我的 config/routes.yaml
文件
index:
path: /
defaults: { _controller: 'App\Controller\GeneratorController::numberAction' }
# Depends on sensio/framework-extra-bundle, doctrine/annotations, and doctrine/cache
# install with composer req sensio/framework-extra-bundle annot
controllers:
resource: ../src/Controller/
type: annotation
这是配置子目录的屏幕截图。我认为我尊重标准:
缓存已成功预热,但还不够。要工作,我也必须清除缓存。
在我的 composer.json 中,我为 post 更新命令添加了一行:
"scripts": {
"auto-scripts": {
"assets:install --symlink --relative %PUBLIC_DIR%": "symfony-cmd",
"security:check": "symfony-cmd",
"cache:clear --no-warmup": "symfony-cmd",
"cache:warmup": "symfony-cmd"
},
"post-install-cmd": [
"@auto-scripts"
],
"post-update-cmd": [
"@auto-scripts"
]
},
添加的行是这一行:"cache:clear --no-warmup": "symfony-cmd"
安装应用程序时不需要此行,但在更新期间需要。