Version: current

# Class ContentNegotiator

The content negotiator performs "text/html" or "application/xhtml+xml" switching. It does this through the static function ContentNegotiator::process(). By default, ContentNegotiator will comply to the Accept headers the clients sends along with the HTTP request, which is most likely "application/xhtml+xml" (see "Order of selection" below).

Order of selection between html or xhtml is as follows:

- if PHP has already sent the HTTP headers, default to "html" (we can't send HTTP Content-Type headers any longer)
- if a GET variable ?forceFormat is set, it takes precedence (for testing purposes)
- if the user agent is detected as W3C Validator we always deliver "xhtml"
- if an HTTP Accept header is sent from the client, we respect its order (this is the most common case)
- if none of the above matches, fallback is "html"

ContentNegotiator doesn't enable you to send content as a true XML document through the "text/xml" or "application/xhtml+xml" Content-Type. Please see http://webkit.org/blog/68/understanding-html-xml-and-xhtml/ for further information.

Package: sapphire\control
See: http://doc.silverstripe.org/doku.php?id=xhtml-support
See: http://doc.silverstripe.org/doku.php?id=contentnegotiator
See: http://doc.silverstripe.org/doku.php?id=html
Located at sapphire/core/control/ContentNegotiator.php

## Methods summary

`public static` | # `set_encoding( mixed $encoding )` Set the character set encoding for this page. By default it's utf-8, but you could change it to, say, windows-1252, to improve interoperability with extended characters being imported from windows excel. Set the character set encoding for this page. By default it's utf-8, but you could change it to, say, windows-1252, to improve interoperability with extended characters being imported from windows excel.
`public static` | # `get_encoding( )` Return the character encoding set bhy ContentNegotiator::set_encoding(). It's recommended that all classes that need to specify the character set make use of this function. Return the character encoding set bhy ContentNegotiator::set_encoding(). It's recommended that all classes that need to specify the character set make use of this function.
`public static` | # `enable( )` Enable content negotiation for all templates, not just those with the xml header. Enable content negotiation for all templates, not just those with the xml header.
`public static` | # `disable( )`
`public static` | # `enabled_for( mixed $response )` Returns true if negotation is enabled for the given response. By default, negotiation is only enabled for pages that have the xml header. Returns true if negotation is enabled for the given response. By default, negotiation is only enabled for pages that have the xml header.
`public static` | # `process( `SS_HTTPResponse` $response )`
`public string` | # `xhtml( `SS_HTTPResponse` $response )` Only sends the HTTP Content-Type as "application/xhtml+xml" if the template starts with the typical "<?xml" Pragma. Assumes that a correct doctype is set, and doesn't change or append to it. Replaces a few common tags and entities with their XHTML representations ( , <img>, ). Only sends the HTTP Content-Type as "application/xhtml+xml" if the template starts with the typical "<?xml" Pragma. Assumes that a correct doctype is set, and doesn't change or append to it. Replaces a few common tags and entities with their XHTML representations ( , <img>, ). #### Parameters $response $response SS_HTTPResponse #### Returns `string` string
`public` | # `html( `SS_HTTPResponse` $response )`

### Magic methods summary

## Properties summary

`protected static string` | $encoding | #
`protected static boolean` | $enabled | #

[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the Silverstripe Forums to ask development related questions. -