8

I have make a assets folder in root directory where application folder exist. now I have assets sibling to application.

Now when I tried to open http://localhost/CodeIgniter/assets/css/bootstrap.min.css in web-page it's not working.

Do someone can help me how I can got it worked.

In a solution I found that writing this line in config file will work but it's not work either by doing this change.

$config['base_url'] = 'http://localhost/CodeIgniter/';

Now please some guideline me how to load CSS file in CI.

solution :-

I have done something wrong in my codeigniter project. I download it again and try these thing again, without anything it's working.

thanks you all of guys. you save my time.

6
  • Try this: glennstovall.com/blog/2012/02/28/… Commented Dec 23, 2012 at 5:31
  • You have not mentioned how exactly you tried other than the config variable setting. :) Commented Dec 23, 2012 at 5:32
  • Also as it seems you are a beginner in CI, I would recommend you to watch the screencasts on nettuts.com "CodeIgniter from scratch series". Commented Dec 23, 2012 at 5:34
  • load URL helper. $this->load->helper('url'); Commented Dec 23, 2012 at 5:36
  • @SibirajPR thanks I have tried it as echo base_url()/myfileurl but it's look like no url work for get the file. Commented Dec 23, 2012 at 5:46

3 Answers 3

13

In constant.php:

define('URL','http://localhost/CodeIgniter/');
define('IMG',URL.'assets/img/');
define('CSS',URL.'assets/css/');
define('JS',URL.'assets/js/');

In config.php:

$config['base_url'] = URL;

In view:

<link rel="stylesheet" href="<?php echo(CSS.'bootstrap.min.css'); ?>">

Hope that helps somewhat.

Sign up to request clarification or add additional context in comments.

1 Comment

what is URL in config.php file ?
2

define general css that used. Open "config.php" within directory CodeIgniter\system\application\config.

$config['css'] = 'mystyles.css';

Create a file named mystyles.css within root application: \CodeIgniter.

$this->load->helper('url');       
$data['css']        = $this->config->item('css'); 

You can load css in views pages like this.

Comments

1

Add below line in your controller action /application/controllers/yourController.php

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

Then add below line to your view file's head tag.

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

Assuming that you have assets/css/ folder is created in your app directory.

<path to your app folder>/assets/css

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.