lithium\template\helper\Html::link()
Creates an HTML link (<a />) or a document meta-link (<link />).
If $url starts with 'http://' or 'https://', this is treated as an external link.
Otherwise, it is treated as a path to controller/action and parsed using
the Router::match() method (where Router is the routing class dependency specified by
the rendering context, i.e. lithium\template\view\Renderer::$_classes).
If $url is empty, $title is used in its place.
Parameters
-
string
$titleThe content to be wrapped by an
<a />tag, or thetitleattribute of a meta-link<link />. -
mixed
$urlCan be a string representing a URL relative to the base of your Lithium application, an external URL (starts with
'http://'or'https://'), an anchor name starting with'#'(i.e.'#top'), or an array defining a set of request parameters that should be matched against a route inRouter. -
array
$optionsThe available options are:
'escape'boolean: Whether or not the title content should be escaped. Defaults totrue.'type'string: The meta-link type, which is looked up inHtml::$_metaLinks. By default it acceptsatom,rssandicon. If atypeis specified, this method will render a document meta-link (<link />), instead of an HTML link (<a />).- any other options specified are rendered as HTML attributes of the element.
Returns
stringReturns an <a /> or <link /> element.
Source
public function link($title, $url = null, array $options = []) {
$defaults = ['escape' => true, 'type' => null];
list($scope, $options) = $this->_options($defaults, $options);
if (isset($scope['type']) && $type = $scope['type']) {
$options += compact('title');
return $this->_metaLink($type, $url, $options);
}
$url = $url === null ? $title : $url;
return $this->_render(__METHOD__, 'link', compact('title', 'url', 'options'), $scope);
}