没有在Resources / config / services.yml上加载的服务,为什么?

时间:2015-04-14 17:24:13

标签: php symfony dependency-injection symfony-2.7

我在这里遇到问题并且我不知道为什么或在哪里失败,也许我会错过一些配置左右,无论如何,我在DependencyInjection\AppExtension.php文件中有这个代码:< / p>

use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;

class AppExtension extends Extension
{
    /**
     * {@inheritdoc}
     */
    public function load(array $configs, ContainerBuilder $container)
    {
        $configuration = new Configuration();
        $config = $this->processConfiguration($configuration, $configs);

        $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
        $loader->load('services.yml');
    }
}

然后在Resources/config/services.yml我有这个:

services:
    pdone.twig.extension:
        class: GroupDCA\PDOneBundle\Extension\PDOneTwigExtension
        tags:
            -  { name: twig.extension }

由于某种原因,没有工作。这意味着我收到了这个错误:

  

过滤器&#34;空&#34;在第1行的PDOneBundle :: pdone.html.twig中不存在

现在,如果我将服务定义移至config/config.yml,我会收到此错误:

  

编译错误:不能对表达式的结果使用isset()(您可以使用&#34; null!== expression&#34;而不是)

这让我觉得捆绑没有通过DependecyInjection,我在这里缺少什么?为什么会有不同的错误?

1 个答案:

答案 0 :(得分:3)

1)您是否已将捆绑包添加到AppKernel

2)我不确定,但我认为你必须遵循Extension类的命名惯例:

  • Bundle的根目录应包含DependencyInjection目录
  • DependencyInjection内,Extension类应命名为<BUNDLE>Extension,而不是&#34; Bundle&#34;后缀。在您的情况下,这将是PDOOneExtension