Reputation: 88
Good evening,
I started using Codeigniter as Framework for my newest projekt... and already got problems on the first page.
I want to link a CSS file to my site. It looks perfectly good in the Code. But just nothing happens.
<html>
<head>
<title>Tec.Net</title>
<?php
$this->load->helper('html');
echo link_tag($data['css']);
?>
</head>
<body>
<h1><?php echo $title ?></h1>
This is the code of my header.php
body {
background-image: url("application/views/images/Console Background.png");
color: white;
}
The standard.css
<html>
<head>
<title>Tec.Net</title>
<link href="localhost/TecNet/standard.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>Home</h1>
<h2>this is a home site</h2> <em>© 2015</em>
</body>
</html>
And at last. The code i receive from Firefox. The Link is perfectly fine. If i try to access it directly from my browser it opens the css file. As inline CSS the code works perfect just that link refuses to work
EDIT: my URL Structure for the controller.
http://localhost/TecNet/index.php/tecnet/view
And the controller itself
<?php
class Tecnet extends CI_Controller {
public function view($page = 'home')
{
if ( ! file_exists(APPPATH.'/views/pages/'.$page.'.php')) {
// Whoops, we don't have a page for that!
show_404();
}
$data['title'] = ucfirst($page); // Capitalize the first letter
$this->load->view('templates/header', $data);
$this->load->view('pages/'.$page, $data);
$this->load->view('templates/footer', $data);
}
}
?>
Upvotes: 1
Views: 1202
Reputation: 2732
I use assests a bit differently in CI, load with controller dynamically, but maybe this can work for you:
<link href="<?php echo base_url(); ?>assets/css/your_style.css" rel="stylesheet" />
just replace path, so they will match to yours
Upvotes: 0
Reputation: 644
since CodeIgniter is based on the Model-View-Controller development pattern. Better you put resoures of css, img, js, etc.. in root
folder instead on view like you did:
background-image: url("application/views/images/Console Background.png");
assume structures:
/standard.css
/assets/img/console-background.png
your standart.css file:
body {
background-image: url("assets/img/console-background.png");
color: white;
}
easy to call in view:
<link rel="stylesheet" href="<?= base_url('standard.css') ?>">
Upvotes: 1
Reputation: 2218
Try to load your style sheet like this:
<link rel="stylesheet" href="<?= base_url('TecNet/standard.css') ?>">
Upvotes: 1