elseym / content-type-negotiation-bundle

此包已被废弃且不再维护。未建议替代包。

允许Symfony2应用根据HTTP Accept头在同一URI下提供不同的内容类型。

dev-master 2012-11-23 14:08 UTC

This package is not auto-updated.

Last update: 2020-01-24 14:48:39 UTC


README

此包可用于在Symfony2应用程序中启用简单的内容类型协商。要使用它,只需在composer.json中将它作为依赖项包含,并在AppKernel中注册包

composer.json:

...
"require": {
	...
	"elseym/content-type-negotiation-bundle": "dev-master"
}
...

app/AppKernel.php:

...
$bundles = array(
	...
	new elseym\ContentTypeNegotiationBundle\elseymContentTypeNegotiationBundle(),
	...
);

用法

此包的关键组件是一个EventListener,它注册kernel.controller事件,并为每个请求选择最佳合适的控制器操作。此决策基于请求的Accept头值。

对于具有如下Accept头的请求

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

此包会尝试使用以下控制器操作之一

  • indexActionHtmlText
  • indexActionHtml
  • indexActionXhtmlXmlApplication
  • indexActionXhtmlXml
  • indexActionXmlApplication
  • indexActionXml
  • indexAction