Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

include css js in view page of codeigniter

hey everyone i'm facing a problem in codeigniter how to include css and jquery.

+application
  +views
    -welcome_message.php
  +assets
     +css
      -template.css
     +js
+system
+user_guide.


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

firebug show path like:-

<link type="text/css" rel="stylesheet" href="http://localhost/CodeIgniter_2.1.3/application/assets/css/template.css">

i don't understand why it's css is not working.

i find this thing on firebug:-

<link type="text/css" rel="stylesheet" href="http://localhost/CodeIgniter_2.1.3/assets/css/template.css">
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /CodeIgniter_2.1.3/assets/css/template.css was not found on this server.</p>
</body></html>
</link>
See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

Best practice is to create an assets Directory outside the APPLICATION Directory not inside.

so you're directory structure would be

+APPLICATION
+ASSETS
+SYSTEM

its up to you how you divide the resources inside the ASSETS DIrectory

now you can use base_url()/assets/your-directories/yourfiles.ext to access whatever you wanted. Or create your own helper

i.e

style_url();
script_url();
image_url();

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...