How to Set Base URL in Yii Framework

后端 未结 7 1901
情深已故
情深已故 2021-02-15 00:48

When I do

print_r(Yii::app()->request->baseUrl)

I get an empty string. A post on the Yii forum says this is blank by default. How can I c

7条回答
  •  时光取名叫无心
    2021-02-15 01:04

    If you are using Url helper to generate urls, you will need to set baseUrl key to UrlManager component

     'urlManager' => [       
            'baseUrl' => 'http://example.com', 
    

    Then you can create absolute url by using Url helper as,

    echo Url::to(['site/index', 'src' => 'ref1', '#' => 'name'], true); // output ===> http://example.com/index.php?r=site%2Findex&src=ref1#name

提交回复
热议问题