【问题标题】:How to Properly set base_url() in codeigniter?如何在 codeigniter 中正确设置 base_url()?
【发布时间】:2018-09-24 07:42:46
【问题描述】:

我正在开发一个基于 codeigniter 的应用程序,我在该 i 页面上创建了一个全局布局页面,我已经包含了 codeigniter 根目录下 assets 文件夹中的所有 css、js 和其他图像。

我已经包含了类似下面代码的那些文件

<link rel="stylesheet" href="<?php echo base_url(); ?>assets/front/website/static/fonts/icomoon-greycom/css/style.css">

当我访问主页https://mypage.com时,它工作正常 它将这些文件加载​​为

https://mypage.com/assets/front/website/static/font/icomoon-greycom/css/style.css

但是当我访问其他链接时。

https://mypage.com/region/india

加载它

https://mypage.com/region/india/assets/front/wesbite/static/font/icon-greycom/css/style.css

但我希望它只加载https://mypage.com/assets/assets/front/wesbite/static/font/icon-greycom/css/style.css

在我的 config.php 页面中

$config['base_url'] = "https://www.mypage.com/";

如何解决这个问题。

【问题讨论】:

标签: php codeigniter


【解决方案1】:

将资产路径放入base_url 函数(根据docs)。

例如

&lt;?php echo base_url('assets/front/website/static/fonts/icomoon-greycom/css/style.css'); ?&gt;

【讨论】:

    【解决方案2】:

    使用这个:

    <link rel="stylesheet" href="<?php echo site_url(); ?>assets/front/website/static/fonts/icomoon-greycom/css/style.css">
    

    【讨论】:

      【解决方案3】:

      可以使用

      href="<?php echo base_url().'assets/front/website/static/fonts/icomoon-greycom/css/style.css'; ?>"
      

      【讨论】:

        猜你喜欢
        • 2017-07-11
        • 2016-12-29
        • 2016-12-11
        • 2018-08-17
        • 2021-09-08
        • 2012-08-01
        • 2017-11-08
        • 2018-07-26
        • 1970-01-01
        相关资源
        最近更新 更多