【问题标题】:Unusual base url in Codeigniter with Chrome带有 Chrome 的 Codeigniter 中不寻常的基本 URL
【发布时间】:2016-02-18 16:33:55
【问题描述】:

我发现 CI (3.03) 的最新稳定版本不寻常,

我尝试了 echo base_url(),它返回了一些不寻常的东西,

**注意:**我已经加载了 URL 助手。

以下代码

$this->load->helper('url');
echo base_url();

在 Firefox 中返回 http://127.0.0.1/(我使用 http://localhost/ 来解释应用程序)。

还有:

http://::1/(我也用过http://localhost/)在 Chrome 中?

帮我解决这个问题。

【问题讨论】:

  • 你在这里设置了url吗? $config['base_url'] = 'http://localhost/project/';

标签: php codeigniter google-chrome firefox


【解决方案1】:

如果你设置了base_url,请从配置文件中删除,

$config['base_url'] = "http://".$_SERVER['HTTP_HOST']."/";

【讨论】:

  • 感谢 Harsh Sanghani 的回复,但我想知道 CI 的 URL 自动猜测出了什么问题?
【解决方案2】:

在您的配置中,使用定义。如下:

define('base_url', 'http://localhost/your_project name/');

然后试试 echo base_url();

【讨论】:

    【解决方案3】:

    确保您已设置基本网址

    $config['base_url'] = 'http://localhost/project/';
    

    有时对我来说这是个问题。

    在旧版本的 CI 中,您可以将其留空,但是。

    现在建议您不要将该 base_url 留空。

    我会自动加载 url helper,因为它是最常见的。

    【讨论】:

    • 感谢您的信息,但我总是将其留空,直到开发结束,并且 CI 的 URL 自动猜测工作正常,这是我第一次遇到问题
    • 留空WARNING: You MUST set this value!是错误的。 Check the comment above.
    猜你喜欢
    • 2016-04-05
    • 1970-01-01
    • 1970-01-01
    • 2013-09-29
    • 2016-02-11
    • 2012-01-24
    • 2012-06-23
    • 2012-09-13
    • 2013-04-25
    相关资源
    最近更新 更多