刚才,我尝试了添加链接到导航栏的内容.例如;
menuItems[] = ['label' => 'Test', 'url' => ['http://www.google.com']];
Run Code Online (Sandbox Code Playgroud)
但是我看到,任何时候yii2都会将baseUrl添加到每个地址.我也是这样做的;
文件:\ vendor\yiisoft\yii2\helpers\BaseHtml.php
之前:
public static function a($text, $url = null, $options = [])
{
if ($url !== null) {
$options['href'] = Url::to($url);
}
return static::tag('a', $text, $options);
}
Run Code Online (Sandbox Code Playgroud)
后:
public static function a($text, $url = null, $options = [])
{
if ($url !== null) {
$options['href'] = Url::to($url,'http');
}
return static::tag('a', $text, $options);
}
Run Code Online (Sandbox Code Playgroud)
它正在工作,但我不知道,这是真的吗?你怎么看?
对于外部链接只需使用原始字符串格式:
menuItems[] = ['label' => 'Test', 'url' => 'http://www.google.com'];
Run Code Online (Sandbox Code Playgroud)