Lena Queen
Lena Queen

Reputation: 751

How to describe an image file on javascript file through codeigniter?

I’m new using codeigniter. I using codeigniter 2.X. I have some question regarding basic course of codeigniter.

  1. What the best suggestion for folder location of our external css/ js /image/another ? For now, i put js/css/or another file on the root, i.e site url/css
  2. How to describe path of image on css and javascript file ? On php its easily that just use <?php echo base_url(); ?> but how in css and javascript?

Both question, I need for the best and experience answer because the answer will be my knowledge base for using codeigniter.

Thank you so much.

Upvotes: 2

Views: 235

Answers (1)

Azam Alvi
Azam Alvi

Reputation: 7055

Store your css/js/image in assets folder or as u want

/www
/code_igniter
    /application
    /assets
        +img
        +css
        +js
    /controllers
    /system

then use it in your view as including it

<link type="text/css" rel="stylesheet" href='<?php echo base_url()?>assets/css/mystyle.css'>
<script type="text/javascript" src='<?php echo base_url()?>assets/js/myjs.js'></script>

into your .htacess file add this code

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

put .htaccess file outside the application folder

Upvotes: 1

Related Questions