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
286 views
in Technique[技术] by (71.8m points)

php - how to load css file in codeigniter

Hi Frnds i cannot able to load css file in codeigniter. so please tell me how to load. Codeigniter sample Directory Structure

  1. views
  2. models
  3. controllers
  4. assets a) stylesheets b) javascript c) images
  5. Config

Controller:

    <?php if (!defined('BASEPATH')) exit('No direct script access allowed');
    class Learnersway extends CI_Controller
    {
        function index()
        {
            $this->load->view('home_learnersway');
        }
    }
    ?>

View

    <html>
    <head>

        <link rel="stylesheet" type="text/css" href=“assets/stylesheets/main.css”   />

    </head>
    <body>
    <div class="wrapper">
    <div class="header">
    <div class="title"><img height="136" src="../images/learnersway.jpg" width="272" /></div>

    <div class="main_menu">
    <ul>
        <li>HTML</li>
        <li>XML</li>
        <li>CSS</li>

    </ul>
    </div>
    </div>

    <div class="main_container">
    <div class="sub_menu">
    <ul>
        <li>HTML Introduction</li>
        <li>HTML Editors</li>
        <li>HTML Basic</li>
        <li>HTML Elements</li>
        <li>HTML Attributes</li>
        <li>HTML Headings</li>
        <li>HTML Paragraphs</li>
        <li>HTML Formatting</li>
        <li>HTML Links</li>
        <li>HTML Head</li>

    </ul>
    </div>

    <div class="sub_container">
    <div>Under Construction...</div>
    </div>
    </div>

    <div class="footer">
    <div class="left">All Rights Reserved @ LearnersWay.com</div>

    <div class="right">
    <ul>
        <li>About Us</li>
        <li>Terms &amp; Privacy Policy</li>

    </ul>
    </div>
    </div>
    </div>
    </body>
    </html>

Note:

Please tell me how to load css file in codeigniter. Even if can tell me how load javascripts and images also. I am a beginner in codeigniter MVC Framework.

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

First go to application/config/autoload.php. Then add $autoload['helper'] = array('html','url');

<link rel="stylesheet" href="<?php echo base_url('assets/stylesheets/main.css')?>"/>
//OR
<?php echo link_tag('assets/stylesheets/main.css')?>

//Image
<?php echo img('asset/images/learnersway.jpg')?>
//OR
<img src="<?php echo base_url('asset/images/learnersway.jpg')?>" />

//Javascript
<script src='asset/javascript/yourscript.js'></script>

Please visit userguide http://ellislab.com/codeigniter%20/user-guide/helpers/html_helper.html


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

...