0

I've looked at other answers involving this question, but still can't get it to work. I'm trying to link my CSS file relatively. I've tried the base_url() concat and it still doesn't work. Maybe I just have a misconception about CI URLs. Anyway, my CSS file is under views->templates->Item_CSS.css

I have tried everything and still get no results. If anyone can help I'd be grateful. Thanks!

2 Answers 2

1

You won't be able to reach that path easily, since codeigniter uses it's index.php (situated in the root) to handle everything. The views folder isn't the base path

What I do is to add a css and js folder in the root of CI (where index.php,.htaccess lies), after that your css routes will be www.example.com/css/mycss.css or base_url().css/mycss.css.

In case you get a forbidden error you might need to modify the .htaccess to allow accessing those folders

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

1 Comment

+1, it makes sense to leave CSS at the root of the site, as it doesn't really fit the definition of a "view", imo.
0

Assuming that you config your base url as:

$config['base_url'] = 'http://www.abc.com/';

and you put the application folder where the system and index.php file is. Then use the following code:

<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>application/views/templates/Item_CSS.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.