lithium\action\Request::accepts()
Returns information about the type of content that the client is requesting.
This method may work different then you might think. This is a convenience method
working exclusively with short type names it knows about. Only those types will be
matched. You can tell this method about more types via Media::type()
.
Note: In case negotiation fails, 'html'
is used as a fallback type.
Parameters
-
boolean|string
$type
Optionally a type name i.e.
'json'
ortrue
.- If not specified, returns the media type name that the client prefers, using
a potentially set
type
param, then content negotiation and that fails, ultimately falling back and returning the string'html'
. - If a media type name (string) is passed, returns
true
orfalse
, indicating whether or not that type is accepted by the client at all. - If
true
, returns the raw content types from theAccept
header, parsed into an array and sorted by client preference.
- If not specified, returns the media type name that the client prefers, using
a potentially set
Returns
string|boolean|arrayReturns a type name (i.e. 'json') or a
boolean or an array, depending on the value of
$type`.
Source
public function accepts($type = null) {
$media = $this->_classes['media'];
if ($type === true) {
return $this->_accept ?: ($this->_accept = $this->_parseAccept());
}
if ($type) {
return ($media::negotiate($this) ?: 'html') === $type;
}
if (isset($this->params['type'])) {
return $this->params['type'];
}
return $media::negotiate($this) ?: 'html';
}