Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
358 views
in Technique[技术] by (71.8m points)

php - How to load css in codeigniter

I am new to codeigniter, and I am using v.2.12. I am getting an error when I try to load the css from the external file.

I create the css folder inside the application folder. And I create the css file in the name of all.css.

In the view file I use the following code to link the css file.

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

But the css file is not loading. I'm getting 404 error. Here is my configuration settings:

$config['base_url'] = 'http://webscarlets.com/ci/index.php';
$config['index_page'] = 'index.php';

Website Link: http://webscarlets.com/ci/index.php/welcome.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

This is how you include CSS files in CodeIgniter:

<?php echo link_tag('css/mystyles.css'); ?>

That snippet will output this HTML:

<link href="http://site.com/css/mystyles.css" rel="stylesheet" type="text/css" />

The function link_tag is in the HTML helper, which must first be loaded.

(Note that you probably shouldn't put your CSS files in /application/css. It's just easier to put them in /css or maybe /assets/css.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...