问题
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"); ?>">
On localhost it generates:
<link rel="stylesheet" type="text/css" href="http://127.0.0.1/radiant/includes/custom/css/slider-settings.css">
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.
My directory structure is
Radiant// root of CI
- application
- system
- includes
----- custom
------css
----navbar-setting.css
----sidebar-setting.css
------js
------common
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.
回答1:
OK well let me explain. this is your css href "http://127.0.0.1/radiant/includes/custom/css/slider-settings.css"
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.
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.
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
来源:https://stackoverflow.com/questions/38996743/how-to-get-correct-css-file-address-in-my-view-using-base-url-codeigniter-meth