How to access css file inside a folder in codeigni

2019-09-19 11:15发布

问题:

I am creating a web page and trying to access a stylesheet which is inside a "application/css/" folder. So how we can access this file and what helper function should use? Below is the head section I used in php file.

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Home</title>
<link href="css/style.css" rel="stylesheet" type="text/css" media="screen" />
</head>

If I use base_url('css/style.css') or link_tag('css/style.css'), it is returning url like 'http://localhost/test/css/style.css' which does not return path of css file.'http://localhost/test' is the base url.

回答1:

It is Not Recommended that you have css or images in applications folder

Create a assets folder in main directory

application
assets
assets > css
assets > images
assets > js
system
index.php

On view use example <?php echo base_url('assets/css/stylesheet.css');?>

Autoload the url helper also.



回答2:

<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Home</title>
<link href="<?php echo base_url('assets/css/style.css'); ?>" />
</head>