How to insert external CSS in Codeigniter 3

4

I would like to know how to insert an external css file into a Codeigniter 3 view. I configured the $ autoload ['helper'] = array ('url'); I tried calling in the following ways:

<link rel="stylesheet" type="text/css" href="<?=site_url('application/views/css/main.css')?>">
<link rel="stylesheet" type="text/css" href="<?=site_url('css/main.css')?>">

I also tested using base_url (); but the results were the same. It prints the html with the correct path but is not applying the styles. If I click on this link inside the browser's source code viewer it redirects me to the codeigniter default 404.

    
asked by anonymous 05.12.2015 / 22:49

1 answer

4

EDIT

Make sure you call the help method on the Controller or the URL helper.

$this->load->helper('url');

ORIGINAL

Use the same base_url () . But then you have to set the URL to return the root folder path of your site.

Assuming a structure like this:

  • www.raiz.com
    • index.php
    • css
      • meucss.css

And you want to include CSS in the index.php file, so base_url would be $config['base_url'] = "http://www.raiz.com/" .

In index.php, you would call the CSS:

<link href="<? echo base_url();?>/css/meucss.css" rel="stylesheet" type="text/css" />

    
05.12.2015 / 23:01