【问题标题】:Why is this link not generated correctly in codeigniter?为什么这个链接没有在 codeigniter 中正确生成?
【发布时间】:2018-03-25 07:04:45
【问题描述】:

我正在使用 codeigniter,但指向我的类别的链接无法正常工作。也许我不了解框架的某些设置。我在我的配置文件中设置了这个基本网址:

$config['base_url'] = 'http://hms.loc';

但是当我点击“主页”类别或任何其他类别时,链接看起来像:

http://localhost/hms/

但应该是:

http://hms.loc

当我点击“房间”类别时,它是:

http://localhost/hms/rooms

如何正确设置?我在哪里可以指定这样的设置?

【问题讨论】:

  • 检查你是如何创建链接的。你应该使用url helper
  • 你能告诉我们你的href代码吗?
  • 我用<li><a href="<?php echo site_url()?>">Home</a> <i>/</i></li>作为主页

标签: php codeigniter hyperlink


【解决方案1】:

您可以使用 URL_Helper 中的 base_url() 或 site_url() 方法。

请查看文档:

https://www.codeigniter.com/user_guide/helpers/url_helper.html

【讨论】:

    【解决方案2】:

    我使用 xampp,我的网络应用文件夹名称是“s_v”,所以我使用

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

    【讨论】:

      【解决方案3】:

      如果你的项目文件夹名称是 hms ,定义 base_url 为

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

      其他明智的检查 html 包含

      <base href="http://localhost/hms/">
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-09-05
        • 1970-01-01
        • 2021-12-20
        • 2017-06-13
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多