How to Set Base URL in Yii Framework

后端 未结 7 1876
情深已故
情深已故 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

    It's most likely blank because your bootstrap file (index.php) is at your web root. If it wasn't, you should see some value. Changing it would defeat it's purpose.

    You would use like:

    href="request->baseUrl; ?>/css/screen.css"
    

    which for most cases wouldn't change the path, but if you did, say, decide to put your Yii app inside a subdirectory, then it would be portable. (Simply remove the http method and hostname above to make it work on the same host the user is on.)

提交回复
热议问题