yii2 Html::a

Html::a($text,$url = null,$options = []) 

$url 可以直接是字符串

// An empty string. This will return the current page's URL
$url = '';

// A normal string. This will use the exact string as the href attribute
$url = 'images/logo.png'; // This returns href='images/logo.png'

// A string starting with a Yii2 alias
$url = '@web/images/logo.png' // This returns href='http://www.example.com/images/logo.png'

$url  是数组

// Basic Yii2 Controller > Method route
$url = ['site/index'];
# Returns /index.php?r=site/index or /site/index (if prettyUrl is enabled)

// As above, but adding extra URL variables
$url = ['site/index', 'page' => 10, 'sort' => 'name'];
# Returns /index.php?r=site/index&page=10&sort=name or /site/index?page=10&sort=name (if prettyUrl is enabled)

// As above, but using an alias
$url = ['@posts'];
# Returns /index.php?r=posts/index or /posts/index (if prettyUrl is enabled), assuming @posts is defined as 'posts/index'

$options
$options = [
    'title' => 'My Super Link',
    'target' => '_blank',
    'alt' => 'Link to Super Website',
];
# This will generate the attributes as such...
# <a href='...' title='My Super Link' target='_blank' alt='Link to Super Website'>...</a>



posted @ 2017-02-10 15:13  Yeah,程序猿  阅读(6568)  评论(0编辑  收藏  举报