Where do I put image files, css, js, etc. in Codeigniter?

前端 未结 14 1135
挽巷
挽巷 2020-11-30 16:57

Where is it acceptable to put css folders and image file folders? I was thinking inside the view folder? However the controller always reroutes the path to the base url so I

相关标签:
14条回答
  • 2020-11-30 17:15

    you can put the css folder inside the assest folder(you name it any name) in the directory of your project as:

    - ci_app
    - application 
    - views      
    - assets 
      - css 
        - style.css 
    

    ... when you want to load that file in a page, you can use base_url()function as this way: <head> <link rel='stylesheet' href='<?php echo base_url();?>assets/css/style.css'> </head> and you are sure to add base_url of your project in the config.php file as this:

    $config['base_url'] = 'http://localhost/ci_app';
    
    0 讨论(0)
  • 2020-11-30 17:16

    No, inside the views folder is not good.

    Look: You must have 3 basic folders on your project:

    system // This is CI framework there are not much reasons to touch this files

    application //this is where your logic goes, the files that makes the application,

    public // this must be your documentroot

    For security reasons its better to keep your framework and the application outside your documentroot,(public_html, htdocs, public, www... etc)

    Inside your public folder, you should put your public info, what the browsers can see, its common to find the folders: images, js, css; so your structure will be:

    |- system/
    |- application/
    |---- models/
    |---- views/
    |---- controllers/
    |- public/
    |---- images/
    |---- js/
    |---- css/
    |---- index.php
    |---- .htaccess
    
    0 讨论(0)
  • 2020-11-30 17:16

    (I am new to Codeigniter, so I don't know if this is the best advice)

    I keep publicly available files in my public folder. It is logical for them to be there, and I don't want to use Codeigniter for something I don't need to use it for.

    The directory tree looks likes this:

    • /application/
    • /public/
    • /public/css/
    • /public/img/
    • /public/js/
    • /system/

    The only files I keep in /public/ are Codeigniter's index.php, and my .htaccess file:

    RewriteEngine On
    RewriteBase /
    
    RewriteRule ^css/ - [L]
    RewriteRule ^img/ - [L]
    RewriteRule ^js/ - [L]
    
    RewriteRule ^index.php(.*)$ - [L]
    RewriteRule ^(.*)$ /index.php?/$1 [L]
    
    0 讨论(0)
  • 2020-11-30 17:17

    add one folder any name e.g public and add .htaccess file and write allow from all it means, in this folder your all files and all folder will not give error Access forbidden! use it like this

    <link href="<?php echo base_url(); ?>application/public/css/style.css" rel="stylesheet" type="text/css"  />
    <script type="text/javascript" src="<?php echo base_url(); ?>application/public/js/javascript.js"></script>
    
    0 讨论(0)
  • 2020-11-30 17:18

    I have a setup like this:

    • application
    • system
    • assets
      • js
      • imgs
      • css

    I then have a helper function that simply returns the full path to this depending on my setup, something similar to:

    application/helpers/utility_helper.php:

    function asset_url(){
       return base_url().'assets/';
    }
    

    I will usually keep common routines similar to this in the same file and autoload it with codeigniter's autoload configuration.

    Note: autoload URL helper for base_url() access.

    application/config/autoload.php:

    $autoload['helper'] = array('url','utility');
    

    You will then have access to asset_url() throughout your code.

    0 讨论(0)
  • 2020-11-30 17:19

    I'm using the latest version of CodeIgniter 3.1.0. The folder structure of it is:

    • system
    • application
    • user_guide
    • assets
      • images
      • js
      • css

    That's where you should put the images, css and js files inside the assets folder.

    0 讨论(0)
提交回复
热议问题