Reputation: 1007
I have a controller in codeigniter by the name of Home, and the code looks as such:
class Home extends CI_Controller {
public function index() {
$this->load->view('foundation_css');
$this->load->view('topbar');
$this->load->view('home_page');
}
}
The foundation_css view contains the foundation css linked, the topbar view contains html that displays a topbar, and the home_page view constructs the basic home page.
This is how the page looks when the url I access is http://localhost/codeigniter/index.php
.
This is how the page looks when the url I access is http://localhost/codeigniter/index.php/home/
.
Why does the CSS disappear when the url changes? Does url with which I access the css file change? if so, how would I remedy the situation? For further information, the url I use is <link rel="stylesheet" type="text/css" href="css/foundation.min.css">
. The tree of files looks as such:
/
css/
-foundation.min.css
application/
controllers/
home.php
views/
foundation_css.php
topbar.php
home_page.php
Upvotes: 0
Views: 114
Reputation: 3170
simply use something like this in your file
<link rel="stylesheet" type="text/css" href="<?php echo $this->base_url();?>css/foundation.min.css">
You have to load the url helper class
in controller
where you call the view part something like
$this->load->helper('url');
$this->load->view('foundation_css');
link of url helper
Upvotes: 1
Reputation: 1663
Use full link for css files.
<link rel="stylesheet" type="text/css" href="<?=base_url();?>path_to_css_folder/css/foundation.min.css">
The main reson is bacause when you change url to /home/ it's like subdirectory for server and he can't found your css folder.
Upvotes: 1