0

I am using codeigniter 3.1. I am trying to read base_url from config file . However hardcode value is working fine for the same . my code to read base_url is :

<link rel="stylesheet" type="text/css" href='<?php echo base_url('assets/css/bootstrap.min.css'); ?>' />
<script src='<?php echo base_url('assets/js/bootstrap.min.js'); ?>' />
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assests/css/styles.css'); ?>' />

My config is as follow :

$config['base_url'] = "http://localhost:63342/CI/";
roy vivek
  • 11
  • 1
  • 6
  • 1
    Possible duplicate of [base\_url() function not working in codeigniter](http://stackoverflow.com/questions/6449386/base-url-function-not-working-in-codeigniter) – Juliën Feb 19 '17 at 12:04
  • You have typo `assests/css/` should be `assets/css/` and make sure you have included url helper in your autoload.php: `$autoload['helper'] = array('url');` or manually in your controller: `$this->load->helper('url');` – Taufik Nur Rahmanda Feb 20 '17 at 03:38
  • this link may help you. https://stackoverflow.com/questions/32913983/codeigniter-3-missing-css-files/44161022#44161022 – Avnish Tiwary May 24 '17 at 14:18

3 Answers3

2

In order to use base_url() you have to load url helper first.Load it in application/config/autoload.php like this..

$autoload['helper'] = array('url');

Make sure that your files must be in root under assets folder.

Hikmat Sijapati
  • 6,869
  • 1
  • 9
  • 19
0

Try changing

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

To

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

Make sure assets in root directory out side of application folder

As you have missed spelt it.

0

try this set folder location this way under CI Folder

CI
 application
 system    
 assets

then css link will be

 <link rel="stylesheet" type="text/css" href='<?php echo base_url('assets/css/bootstrap.min.css'); ?>' />
<script src='<?php echo base_url('assets/js/bootstrap.min.js'); ?>' />
<link rel="stylesheet" type="text/css" href='<?php echo base_url('assets/css/styles.css'); ?>' />

make sure to load url helper

$autoload['helper'] = array('url');
Parvez Ahmed
  • 650
  • 7
  • 16