gpt4 book ai didi

php - Yii2 获取绝对主页 url

转载 作者:行者123 更新时间:2023-12-03 02:11:12 25 4
gpt4 key购买 nike

我试图使用 yii2 获取我的应用程序构建的基本 url,我尝试了以下操作。

var_dump(Yii::$app->request->baseUrl)) // Output string(0) ""
var_dump(Yii::getAlias('@web')); // Output string(0) ""
var_dump(Yii::$app->homeUrl); // string(10) "/dashboard"
var_dump(Url::base()); // Output string(0) ""

我的网址是。 https://sub.sampledomain.com/dashboard/products我想要得到“https://sub.sampledomain.com

知道为什么所有这些都无法获取基本 URL 吗?

最佳答案

您需要使用Url::home(),但将$schema参数设置为true:

use yii\helpers\Url;

...

$absoluteHomeUrl = Url::home(true); // http://0.0.0.0:8000/

对于 https,将 $schema 参数设置为 https:

use yii\helpers\Url;

...

$httpsAbsoluteHomeUrl = Url::home('https'); // https://0.0.0.0:8000/

关于php - Yii2 获取绝对主页 url,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50362752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com