如何在 Yii 框架中设置 Base URL [英] How to Set Base URL in Yii Framework

查看:37
本文介绍了如何在 Yii 框架中设置 Base URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我这样做

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

我得到一个空字符串.Yii 论坛上的一个帖子说 这是空白的默认.如何更改其默认值以便我可以使用绝对 URL?

I get an empty string. A post on the Yii forum says this is blank by default. How can I change its default value so that I can use absolute URLs?

推荐答案

正如该论坛中的帖子所说,对于不同的平台,或者如果 Web 应用程序不在默认文件夹中,它可能会有所不同.
所有这些都对我有用:

As the post in that forum says, it might be different for different platforms, or if the web app isnt located in the default folder.
All these things work for me:

echo Yii::app()->request->baseUrl."<br/>" ;
print_r(Yii::app()->request->baseUrl);
echo "<br/>";
var_dump(Yii::app()->getBaseUrl(true));
echo "<br/>";
echo Yii::app()->request->getBaseUrl(true);

我使用 yiic 创建 Web 应用程序,在终端中使用以下命令使用默认设置,yiic webapp/path/to/webapp
这样就为 Web 应用程序生成了必要的目录结构,以及默认的骨架文件.尝试一下,然后看看它是如何工作的.我自己是 yii 的新手.

I used yiic to create the web app, with default settings using the following command in a terminal, yiic webapp /path/to/webapp
So that generates the necessary directory structure for the web app, and also the default skeleton files. Try it and then see how it works. I'm new to yii myself.

此解决方案可能适用于操作,但可以设置 baseUrl 的正确方法由 ecco 对此问题的回答.

This solution might have worked for the op, but the correct way baseUrl can be set is shown by ecco's answer to this question.

这篇关于如何在 Yii 框架中设置 Base URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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