Posts

Showing posts from 2013

Loading CSS file in CodeIgnitor

Loading CSS file in CodeIgnitor
I was wondering hours and hours how to load css files in CodeIgnitor. For the beginners this is  musch embarrassing. So dear beginners here is how to do it.

Lets have a sample view and a controller.

View- application/views/myView.php
Controller- application/controllers/myController.php

And its a good practice to have your in a separate directory. Here I keep my css files in a directory under application folder.

CSS file- application/styles/myStyle.css

myController.php
<?php

    class MyController extends CI_Controller{

        functionMyController{
            parent::__construct();
        }

        function load_home_view(){
            $this->load->helper('url');
            $this->load->view("myView");
        }

    }
?>


myView.php
<html>

    <head>
        <link rel="stylesheet" type="text/css" href="<?php echo base_url();?>/styles/myStyle.css">
    </head>

    <body>
    …