How to load external CSS by CodeIgniter?

3

I need to call this external style sheet, but it does not load at all, I saw a similar question here, but I did not notice a conclusive answer, since I am using CodeIgniter 3 below.

The error that appears is this:

  

Failed to load resource: the server responded with a status of 404 (Not Found)

How could you solve this problem?

<!DOCTYPE html>
<html lang="pt-br">
<head>
    <meta charset="utf-8"/>
    <title>RR Telecon</title>
    <link rel="shortcut icon" href="images/favicon.ico" />
    <link rel="icon" href="images/favicon.ico" type="image/x-icon" />
    <link href="<?php echo base_url(); ?>/assets/css/bootstrap-theme.css" rel="stylesheet" type="text/css"/>
    <link href="<?php echo base_url(); ?>/assets/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css"/>
    <link href="<?php echo base_url(); ?>/assets/css/bootstrap.css" rel="stylesheet" type="text/css"/>
    <link href="<?php echo base_url(); ?>/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
    <link href="<?php echo base_url(); ?>assets/css/home.css" rel="stylesheet" type="text/css"/>
</head>
<body>
    <section class="reader">
        teste
    </section>
</body>
</html>
    
asked by anonymous 10.02.2016 / 21:29

2 answers

1

Error 404 means that it is not finding the file in the specified location. In the browser console, which line is giving the error? from what I saw there, a slash (/) is missing after base_url when you call home.php. That may be your problem. replace with the code below and test.

<link href="<?php echo base_url(); ?>/assets/css/bootstrap-theme.css" rel="stylesheet" type="text/css"/>
<link href="<?php echo base_url(); ?>/assets/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css"/>
<link href="<?php echo base_url(); ?>/assets/css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="<?php echo base_url(); ?>/assets/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="<?php echo base_url(); ?>/assets/css/home.css" rel="stylesheet" type="text/css"/>

But you would have to see if your base_url has the slash (/) at the end. if it does, you will need to remove all the bars when you place the link. Staying this way:

    <link href="<?php echo base_url(); ?>assets/css/bootstrap-theme.css" rel="stylesheet" type="text/css"/>
<link href="<?php echo base_url(); ?>assets/css/bootstrap-theme.min.css" rel="stylesheet" type="text/css"/>
<link href="<?php echo base_url(); ?>assets/css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="<?php echo base_url(); ?>assets/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<link href="<?php echo base_url(); ?>assets/css/home.css" rel="stylesheet" type="text/css"/>

Test both ways and see what happens:)

    
29.02.2016 / 02:55
0

Use the directory within the function base_url() , and to shorten the call a little more, use <?= and ?> instead of <?php echo and ; ?> .

Example:

<link rel="stylesheet" type="text/css" href="<?=base_url('assets/css/bootstrap-theme.css')?>">
<link rel="stylesheet" type="text/css" href="<?=base_url('assets/css/bootstrap-theme.min.css')?>">
<link rel="stylesheet" type="text/css" href="<?=base_url('assets/css/bootstrap.css')?>">
<link rel="stylesheet" type="text/css" href="<?=base_url('assets/css/bootstrap.min.css')?>">
<link rel="stylesheet" type="text/css" href="<?=base_url('assets/css/home.css')?>">

See how the code got cleaner and nicer to read.

    
15.03.2016 / 08:54