To get base URL of application you should use yiihelpersUrl::base()
method:
use yiihelpersUrl;
Url::base(); // /myapp
Url::base(true); // http(s)://example.com/myapp - depending on current schema
Url::base('https'); // https://example.com/myapp
Url::base('http'); // http://example.com/myapp
Url::base(''); // //example.com/myapp
Url::home()
should NOT be used in this case. Application::$homeUrl
uses base URL by default, but it could be easily changed (for example to https://example.com/myapp/home
) so you should not rely on assumption that it will always return base URL. If there is a special Url::base()
method to get base URL, then use it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…