示例#1
0
 /**
  * Returns the code for a link.
  *
  * @param string $label   The label
  * @param string $url     The URL
  * @param array  $options Options for the URL code (class, title, etc)
  *
  * @return string
  */
 public static function link($label, $url = null, array $attributes = array())
 {
     // If the URL is null, use the label
     if ($url === null) {
         $url = $label;
     }
     // If the URL parameter is an object, call its `href()` method.
     if (is_object($url) and method_exists($url, 'href')) {
         $url = $url->href();
     }
     // Is this a local link?
     if (substr($url, 0, 4) !== 'http' && substr($url, 0, 2) !== '//') {
         $url = Request::basePath($url);
     }
     $attributes['href'] = $url;
     $attributes = static::buildAttributes($attributes);
     return "<a {$attributes}>{$label}</a>";
 }