PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, January 21, 2022

[FIXED] Including External stylesheet in CodeIgniter

 January 21, 2022     codeigniter, php     No comments   

Issue

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.


Solution

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"/>


Answered By - MonkeyZeus
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing