Creates an HTML anchor to a file. Note that the title is not escaped, to allow HTML elements within links (images, etc).
echo HTML::file_anchor('media/doc/user_guide.pdf', 'User Guide');
string Core_HTML::file_anchor( string $file [, string $title = null , array $attributes = null , string $protocol = null ] )
参数列表
参数 类型 描述 默认值 $file
string
Name of file to link to $title
string
Link text null $attributes
array
HTML anchor attributes null $protocol
string
Non-default protocol, eg: ftp null
string
public static function file_anchor($file, $title = null, array $attributes = null, $protocol = null)
{
if ($title === null)
{
// Use the file name as the title
$title = basename($file);
}
// Add the file link to the attributes
$attributes['href'] = Core::url()->base(false, $protocol) . $file;
return '<a' . HTML::attributes($attributes) . '>' . $title . '</a>';
}