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
693 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 Answer

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();

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

...