我正在尝试设置 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/