几个小时以来,我一直在努力做出你能想象到的最简单的事情而且它不起作用.我已经阅读了大量的stackoverflow问题,阅读有关配置文件的完整Symfony文档以及我阅读的每篇文章或其他信息,它变得越来越难以理解.
我创建了自己的Bundle.让我们来称呼它HappyBundle.我把这个Bundle放在我公司的文件夹里.所以我很自然CompanyHappyBundle.
我想专门为这个bundle创建一个配置文件,因为我希望它可以重用.
当我测试我创建了以下内容:
# src/Company/HappyBundle/Resources/config/config.yml
company_happy:
import:
path: /tmp
Run Code Online (Sandbox Code Playgroud)
现在,我想要的是能够在我的控制器中使用此值.我只是不知道如何.它抛出以下错误:
[Symfony\Component\Config\Exception\FileLoaderLoadException]
There is no extension able to load the configuration for "company_happy" (in /home/user/symfony/src/Company/HappyBundle/Resources/config/config.yml).
Looked for namespace "company_happy", found "framework", "security", "twig", "monolog", "swiftmailer", "assetic", "doctrine", "sensio_framework_extra", "debug", "web_profiler", "sensio_distribution" in /home/user/symfony/src/Company/HappyBundle/Resources/config/config.yml (which is being imported from "/home/user/symfony/app/config/config.yml").
Run Code Online (Sandbox Code Playgroud)
在config.yml中我添加了以下内容:
#app/config/config.yml
imports:
- { resource: "@CompanyHappyBundle/Resources/config/config.yml" }
Run Code Online (Sandbox Code Playgroud)
我也做了一个Configuration类,因为我读到了这个必需的地方.我真的认为这只是一个配置文件的工作.
namespace Company\HappyBundle\DependencyInjection;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
use Symfony\Component\Config\Definition\ConfigurationInterface;
class Configuration implements ConfigurationInterface
{
/**
* {@inheritDoc}
*/
public …Run Code Online (Sandbox Code Playgroud)