Reputation: 500
This Is hardik vyas, new to CodeIgniter, I have basic know-how about CodeIgniter. I want to include a template into CodeIgniter, but first of all I need to include an external stylesheet in a page, But I can't, I am facing a 403 error.
Here is my code:
Controller header.php
<?php
class Header extends CI_Controller{
function index(){
$this->load->view('header');
}
}
?>
View header.php
<html>
<head>
<title>demo</title>
<link rel="stylesheet" type="text/css" href="/application/views/mystyle.css"/>
</head>
<body style="background-color: antiquewhite">
<h3 style="background-color: #990000;color: #ffffff">Hello</h3>
</body>
</html>
CSS mystyle.css
.red {
background-color: red;
}
Please provide any simple way to do this and also please show me a simple way about how to include a template in CodeIgniter.
Upvotes: 0
Views: 4478
Reputation: 20737
Your stylesheet(s) should not be inside of the CodeIgniter views
folder.
You folders should look like this:
/index.php
/css/mystyle.css
/codeigniter/application/controllers
/codeigniter/application/models
/codeigniter/application/views // <- no CSS in here
So your view should be:
<link rel="stylesheet" type="text/css" href="/css/mystyle.css"/>
If you want CSS in your views folder then I suggest this:
Folder
/codeigniter/application/views/css/mystyle.css
Code
<link rel="stylesheet" type="text/css" href="/codeigniter/application/views/css/mystyle.css"/>
Upvotes: 2
Reputation:
Put your CSS wherever you’d like, then target that url.
Try putting it in the folder ‘/views/mystyle.css
’ for instance ‘/’ being the root of your site, not your CI install.
From CI, you can then call it with
<?= link_tag(base_url().'views/mystyle.css'); ?>
Upvotes: 1
Reputation: 1796
try like this
<link rel="stylesheet" type="text/css" href="<?php echo base_url()?>views/mystyle.css"/>
Upvotes: 0