如何使用base_url()CodeIgniter方法在我的视图中获取正确的CSS文件地址 [英] How to get correct CSS file address in my view using base_url() CodeIgniter method

查看:129
本文介绍了如何使用base_url()CodeIgniter方法在我的视图中获取正确的CSS文件地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在CodeIgniter中开发一个项目,但面临以下问题:

I am developing a project in CodeIgniter but facing the following problem:

我的视图文件(标题)中包含以下代码:

I have following codes inside my view file(header):

<link rel="stylesheet" type="text/css" href="<?php echo base_url("includes/custom/css/slider-settings.css"); ?>">

在本地主机上会生成:

<link rel="stylesheet" type="text/css" href="http://127.0.0.1/radiant/includes/custom/css/slider-settings.css">

在本地主机上运行每个css& js文件已完美加载。但是,当我将其上传到实时服务器(到现有网站的子域)时,那里没有文件。我一直在尝试解决所有可能的方法,但无法解决。

There is no problem when running on localhost every css & js files being loaded perfectly. But When I upload it to live server(to a subdomain of an existing website) no file is getting included there. I have been trying to solve it all the way possible but couldn't.

我的目录结构是

Radiant// root of CI
      - application
      - system
      - includes
        ----- custom
              ------css
                   ----navbar-setting.css
                   ----sidebar-setting.css
              ------js
              ------common

在localhost中没有问题,但是当上传到子域时,不包含文件。

In localhost there is no problem but when uploaded to a subdomain, no file is being included.

任何与此有关的帮助将不胜感激。

Any help regarding this would be greatly appreciated.

推荐答案

好好,让我解释一下。这是您的css href http://127.0.0.1/radiant/includes/custom/css/slider-settings.css

OK well let me explain. this is your css href "http://127.0.0.1/radiant/includes/custom/css/slider-settings.css"

在这里,此路径 includes / custom / css / slider-settings.css 是CSS文件的绝对路径。因此,正如您在文件结构中添加的那样,路径上没有问题。这是 http://127.0.0.1/radiant/ 基本url定义的路径。

In here this path includes/custom/css/slider-settings.css is the absolute path of your CSS file. So as you have added in file structure there is no issue on the path. And this is http://127.0.0.1/radiant/ base url defined path.

所以当我们来到到 base_url 到另一种会有所不同。这意味着您在 config.php base_url()中设置的内容将在您调用的任何地方回显该值。

So when we came to base_url it will be various from one to another. It means what you set in config.php base_url() it will echo the value where ever you called.

一直以来,我们都使用基本URL作为项目的根文件夹。您在问题 到现有网站的子域 中提到了。这意味着在 config.php baseurl应该看起来像这样(看第二个)

All the time we use base URL as our project root folder. You mentioned on the question to a subdomain of an existing website. It means in config.php baseurl should look like this(look at second one)

$config['base_url'] = 'http://stackoverflow.com/'; # root folder of the host
$config['base_url'] = 'http://chat.stackoverflow.com/'; subdomained pointed URL

这篇关于如何使用base_url()CodeIgniter方法在我的视图中获取正确的CSS文件地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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