【问题标题】:Unable to replace alias "templating" with "fos_rest.templating"无法用“fos_rest.template”替换别名“模板”
【发布时间】:2016-01-07 15:56:28
【问题描述】:

我正在尝试设置 Symfony3 microkelner 以与 FOSRestBundle 一起使用,但我遇到了一些问题。

我想将 json 或 xml 用作输入,也将 json 或 xml 用作输出。

我进行了一些设置,但遇到了错误:

ContainerBuilder.php 第 766 行中的 InvalidArgumentException: 服务定义“模板化”不存在。

ReplaceAliasByActualDefinitionPass.php 第 48 行中的 InvalidArgumentException: 无法将别名“模板”替换为“fos_rest.template”。

这就是我的 config.yml 的样子(带有模板和 fos_rest 的部分)

# Friends of Symfony REST
fos_rest:
  disable_csrf_role: ROLE_API
  view_response_listener: force
  force_redirects:
    html: true
      param_fetcher_listener: true
      body_listener:
        decoders:
          xml: fos_rest.decoder.xml
          json: fos_rest.decoder.json
      format_listener:
        enabled: true
        rules:
          - { path: '^/', priorities: ['json', 'xml'], fallback_format: 'json', prefer_extension: false }
      view:
        formats:
          xml: true
          json: true
        default_engine: json
        failed_validation: HTTP_BAD_REQUEST

还有

templating:
    engines: ['twig']
....
# Twig Configuration
twig:
    debug:            "%kernel.debug%"
    strict_variables: "%kernel.debug%"
    exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'

在 microkelner 中,我使用以下捆绑包:

  $bundles = array(
        new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
        new FOS\RestBundle\FOSRestBundle(),
        new JMS\SerializerBundle\JMSSerializerBundle(),
        new Symfony\Bundle\TwigBundle\TwigBundle(),
    );

    if (in_array($this->getEnvironment(), array('dev', 'test'), true)) {
        $bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
    }

我使用的组件版本:

  • FOSRestBundle:“1.7.7”
  • Symfony:“3.0.0”

问题是如何正确设置它以消除此错误并使带有 microkelner 的 Symfony3 与 FOSRestBundle 一起使用?

谢谢。

【问题讨论】:

  • 我面临同样的问题,有什么解决办法

标签: php fosrestbundle symfony


【解决方案1】:

您确定您的配置正确吗?当我倾倒容器时:

$ bin/console debug:container | grep fos

我在许多其他行中看到:

fos_rest.templating            alias for "templating"   

所以fos_rest.templating 只是templating 的别名,这可能就是为什么你可以用它自己替换它,因此这两个错误。

【讨论】:

  • 我决定在 2.8 上以相同的配置运行项目,它可以工作
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-25
  • 1970-01-01
  • 2023-01-12
  • 1970-01-01
  • 1970-01-01
  • 2012-11-21
相关资源
最近更新 更多