2016-09-09 63 views

回答

1

是啊,就像这样:

<?= \yii\helpers\Url::to('http://www.anothersite.com/action') ?> 

但是,这是一样的:

<?= 'http://www.anothersite.com/action' ?> 

如果你想有使用的路线另一个网站(所以你可以使用与操作数组路线参数例如),你需要首先配置其他网站的urlManager,否则它将无法工作。

+0

谢谢你的回答,我试了一个星期前,但它显示了'mysite.com/http://www .anothersite.com/action'。我不想使用路线。只要给网址。 –

+0

你如何调用它? – Bizley

+0

我敢打赌,你使用'Url :: toRoute'或'Url :: to'来代替字符串。 – Bizley

1

这灵魂是可重复使用的,所以试试看。

在应用程序的配置文件中定义一个别名。

Yii::setAlias('@another', 'http://anothersite.com/action'); 

然后你就可以使用它贯穿整个应用程序一样,

//assuming you've already imported yii\helpers\Url 
Url::to('@another');