Getting base URL in Yii 2

后端 未结 10 2438
孤独总比滥情好
孤独总比滥情好 2020-12-30 19:32

I am trying to get the base URL for the project in Yii 2 but it doesn\'t seem to work. According to this page you used to be able to do:

Yii::app()->getBa         


        
相关标签:
10条回答
  • 2020-12-30 20:29

    To get base URL Yii2 using:

    Url::home(true)
    
    0 讨论(0)
  • 2020-12-30 20:30

    Try this:

    $baseUrl = Yii::$app->urlManager->createAbsoluteUrl(['/']);
    
    0 讨论(0)
  • 2020-12-30 20:32

    My guess is that you need to look at aliases.

    Using aliases would be like:

    Yii::getAlias('@web');
    

    You can also always rely on one of these two:

    Yii::$app->homeUrl;
    
    Url::base();
    
    0 讨论(0)
  • 2020-12-30 20:33

    may be you are looking for this

    Yii::$app->homeUrl
    

    you can also use this

    Url::base().
    

    or this

    Url::home();

    0 讨论(0)
提交回复
热议问题