php - 无法用 "templating"替换别名 "fos_rest.templating"

标签 php fosrestbundle symfony

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

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

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

InvalidArgumentException in ContainerBuilder.php line 766: The service definition "templating" does not exist.

InvalidArgumentException in ReplaceAliasByActualDefinitionPass.php line 48: Unable to replace alias "templating" with "fos_rest.templating".

这是我的 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”
  • 交响乐:“3.0.0”

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

谢谢。

最佳答案

你确定你的配置是正确的吗?当我转储容器时:

$ bin/console debug:container | grep fos

我在许多其他行中看到:

fos_rest.templating            alias for "templating"   

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

关于php - 无法用 "templating"替换别名 "fos_rest.templating",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34659557/

相关文章:

rest - 如何使用 FosRestBundle 公开函数结果?

api - Symfony2 FosRestBundle 根 api url

javascript - 使用 HREF 重定向到新页面之前设置 PHP session 变量

php - 连接失败: 2002

php - 扩展 PHP Markdown 以接受 CSS 类名

php - 交响乐团 : clear cache and warmup when users are using the website

php - 尝试使用 phpMyAdmin 创建 Doctrine 数据库时出错

php - Snowfire/Beautymail Laravel 无法将数据推送到主题和 View 中

symfony - Symfony2 中使用 FOSUserBundle(和 HWIOauthBundle)进行简单 API key 身份验证,填补了空白

javascript - 如何将 twig 代码从 javascript 传递到 twig 文件?