Yii框架中homeUrl和baseUrl的区别是什么? [英] What is the difference between homeUrl and baseUrl in Yii framework?

查看:29
本文介绍了Yii框架中homeUrl和baseUrl的区别是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Yii 框架中的 homeUrlbaseUrl 有什么区别?

What is the difference between homeUrl and baseUrl in Yii framework?

推荐答案

来自文档:

baseUrl:

返回应用程序的相对 URL.这类似于scriptUrl 只是它没有脚本文件名,并且结束斜线被剥离.

Returns the relative URL for the application. This is similar to scriptUrl except that it does not have the script file name, and the ending slashes are stripped off.

虽然,homeUrl

主页网址

尝试在您的应用程序中的某处回显以自己检查每个:

Try echoing somewhere at your application to examine each by yourself:

echo Yii::app()->getBaseUrl(true);// true tells to get a relative url, false the other way
echo Yii::app()->getHomeUrl();

如何使用每个?

baseUrl 就像@bcmcfc 所说的那样,可以用作应用程序中所有链接的基础.

baseUrl is as @bcmcfc said can be useful as a base for all links in your applications.

现在假设您想链接到 web_root/myapp/img/ 中的图像,例如,如果您使用绝对路径(例如 <img src="C:/wwww/myapp/img/somepic.jpg> 假设你已经完成了所有的开发,现在你想要部署到某个 linux 服务器上!!

Now imagine you wanted to link to an image in web_root/myapp/img/ if for example you did that using absolute path e.g <img src="C:/wwww/myapp/img/somepic.jpg> Let's say you finished all your development and now you want to deploy to some linux server!!

你可以看到你所有的链接都被破坏了 :( 但如果你这样做了: <img src= <?php Yii::app()->baseUrl() ?> ."/img/somepic.jpg" 一切正常:)

You can see that all your links will be broken :( but if instead you did: <img src= <?php Yii::app()->baseUrl() ?> . "/img/somepic.jpg" Everything should work fine :)

homeUrl 只是您应用的着陆页.好吧,我之前没有使用过这个,但我想你可以根据登录后的用户角色设置不同的 homeurls !

homeUrl is simply the landing page for your app. Well i didn't use this before but i guess you can set diffirent homeurls according to User role after login for example!!

这篇关于Yii框架中homeUrl和baseUrl的区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆