0

I Just downloaded CodeIgniter 2.1.3 and Trying to import css into via header_controller,

I have tried SOF: CodeIgniter - Loading CSS, CI_Help_page and codeigniter CSS problem (SitePoint Form Thread). I'm currunlty utterly confuse and Can't find the simple Answer. Does any one out there has a one step answer on how to Import CSS and JS on CodeIgniter version 2.1.3.

I have : register.php

<?php

class register extends  CI_Controller {

    public function index()
    {

        //Get header
        $this->load->view('header');

        //Any other class
        $this->load->view('register');

    }
}

than header.php

<?php

?>

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html;charset=UTF-8">
        <link rel="stylesheet" href="<?php echo base_url();?>css/bootstrap.css" type="text/css" media="screen"/>

        <title>DMP</title>
    </head>
    <body>

Here is my project folders: Project folders.png (incase you want to guid me on where can I place CSS)

Thanks.

Community
  • 1
  • 1
DPP
  • 12,716
  • 3
  • 49
  • 46
  • What does not work for you? Is the URL you output wrong? – hakre May 17 '13 at 11:20
  • @hakre So When i add tag in header, The page goes blank and nothing gets outputted. – DPP May 17 '13 at 11:24
  • *"The page goes blank and nothing gets outputted"* - That's a very common error, please see the [PHP Error Reference](http://stackoverflow.com/q/12769982/367456), IIRC it's the first entry there. – hakre May 17 '13 at 11:27
  • load the url helper in your controller... $this->load->helper('url') and follow the comment of @hakre – thpl May 17 '13 at 11:39

3 Answers3

2

Only guessing, but in order to be able to use base_url() you need to load the url helper in your controller. Also, as @hakre already said in the comments turn on your error reporting.

class register extends  CI_Controller {

    public function index()
    {
        $this->load->helper('url');

        //Get header
        $this->load->view('header');

        //Any other class
        $this->load->view('register');

    }
}
thpl
  • 5,810
  • 3
  • 29
  • 43
  • Simple, Master piece of line ever! You can Thumbs-up to my que. if you like. – DPP May 17 '13 at 11:55
  • 1
    To add on to that, 1) autoloading the URL helper is extremely useful, and 2) `base_url` accepts a string argument for anything that should come after the base URL. It makes outputting easier. E.g. `echo base_url('css/bootstrap.css');` – Aken Roberts May 17 '13 at 22:14
1

This should work

<link rel="stylesheet" href="<?php echo base_url('css/bootstrap.css')?>" type="text/css" media="screen"/>
Pooshonk
  • 1,284
  • 2
  • 22
  • 49
0

Add this on your view page:

 <link rel="stylesheet" href="<?php echo base_url();?>css/bootstrap.css" type="text/css" media="screen"/>
Vijaya Pandey
  • 4,252
  • 5
  • 32
  • 57