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>




免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM