gpt4 book ai didi

php - 如何覆盖 Symfony 4 中第三方包的资源?

转载 作者:可可西里 更新时间:2023-11-01 12:46:43 29 4
gpt4 key购买 nike

我使用 Symfony Flex 重新安装了 Symfony,新框架属于下一个 Symfony 4 目录结构。接下来,I'm going to override some resources例如来自外部包的模板、翻译等。

我已经尝试为模板创建所有这些路径(开始)但没有任何效果:

  • templates/EasyAdminBundle/views/...
  • templates/Resources/EasyAdminBundle/views/...
  • app/Resources/...(只是旧结构的证明)

我应该将我的资源文件放在哪里以覆盖第三方包资源?

最佳答案

对于所有 Symfony 版本,资源路径是 %kernel.root_dir%/Resources/ 。由于新的4.0结构将Kernel.php放到了src/目录下,所以是:

# local resources directory
src/Resources/
# still works this path for local templates
src/Resources/views/

# override resources for third-party bundles
src/Resources/AcmeDemoBundle/views/ # legacy convention to override templates
src/Resources/AcmeDemoBundle/translations/ # for override both translations and validations files
src/Resources/AcmeDemoBundle/... # etc.

覆盖资源的新约定(自 Symfony 3.4 起)

Twig Templates :只需遵循约定:

templates/bundles/AcmeDemoBundle/path/to/template.html.twig

If you are upgrading to Symfony 3.4 & 4.0 and you want to use the previous templates conventions, configure your own Twig's paths:

# app/config/config.yml (3.3)
twig:
paths:
# Default templates directory, since 3.4+
templates: ~

# Directory convention to override bundle templates, since 3.4+
# make sure to know the actual Twig namespace for each bundle.
# e.g. AcmeDemoBundle -> AcmeDemo:
templates/bundles/AcmeDemoBundle: AcmeDemo

Translations:templates/ 类似,您在项目的根目录下有 translations/ 目录(默认情况下):

translations/bundles/AcmeDemoBundle/messages.en.yml

注意:/bundles/AcmeDemoBundle/ 子目录不是 是强制性的,因为翻译与包无关,而是与域相关。这意味着您可以覆盖翻译,只要它在正确的域中即可。

关于php - 如何覆盖 Symfony 4 中第三方包的资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45239350/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com