Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我从一开始就需要一个 url,就像 localhost/myApp/index.php?r=controller/action/id 我在 localhost 和 www.sitename.com/index.php?r=controller/action/id. 稍后我会更改格式以使其对 SEO 友好,但现在 Yii::app()->baseUrl 给出myApp/ 了我可以在 Yii 中使用什么功能从基础生成 url。显然我已经使用它了。但现在无法在API中找到它。
localhost/myApp/index.php?r=controller/action/id
www.sitename.com/index.php?r=controller/action/id
myApp/
解决了它:
echo Yii::app()->createAbsoluteUrl('site/index');
从API本身。这将为您提供从根本上的路径。
您可以使用以下功能:
Yii::app()->getRequest()->getBaseUrl(true)