CSS is not loading when using segment URI in codeigniter -


why css not loading when using segment uri in codeigniter working when remove segment ?

not_loading

this how link css file

<title>title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="content-type" content="text/html; charset=utf-8" />  <!-- bootstrap --> <link href="public/css/bootstrap.css" rel='stylesheet' type='text/css' media="all" /> <!-- //bootstrap --> <!-- custom theme files --> <link href="public/css/style.css" rel='stylesheet' type='text/css' media="all" />  <script src="public/js/jquery-1.8.3.min.js"></script> 

controller

<?php if ( ! defined('basepath')) exit('no direct script access allowed');  class profiles extends ci_controller {          public function index() {               $user_id = $this->uri->segment(2, 9);          $this->load->model('user_model');     $this->load->model('count_model');               $data   = array();       $result =  $this->user_model->read_user_information_profile($user_id);               $data = array(     'username' => $result[0]->username,     'fname' => $result[0]->fname,     'lname' => $result[0]->lname,          );     $this->load->view('profiles_view', $data);     }  } 

thanks in advance

because using relative urls loading css, it's trying load /dir/profiles/public/css/style.css instead of /dir/public/css/style.css hence why doesn't load.

you can either use absolute urls in css with:

<link href="<?php echo base_url('public/css/style.css'); ?>" rel='stylesheet' type='text/css' media="all" /> 

or set base tag before try load css or js:

<base href="<?php echo base_url(); ?>" /> 

see: http://www.codeigniter.com/user_guide/helpers/url_helper.html#base_url, note may need load url helper if you're not already.


Comments

Popular posts from this blog

How has firefox/gecko HTML+CSS rendering changed in version 38? -

javascript - Complex json ng-repeat -

jquery - Cloning of rows and columns from the old table into the new with colSpan and rowSpan -