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

前端 未结 14 1236
挽巷
挽巷 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:11

    This is how I handle the public assets. Here I use Phalcon PHP's Bootstrap method.

    Folder Structure

    |-.htaccess*
    |-application/
    |-public/
      |-.htaccess**
      |-index.php***
      |-css/
      |-js/
      |-img/
      |-font/
      |-upload/
    |-system
    

    Files to edit

    1. .htaccess*

      All requests to the project will be rewritten to the public/ directory making it the document root. This step ensures that the internal project folders remain hidden from public viewing and thus eliminates security threats of this kind. - Phalconphp Doc

      
          RewriteEngine on
          RewriteRule  ^$ public/    [L]
          RewriteRule  (.*) public/$1 [L]
      
      
    2. .htaccess**

      Rules will check if the requested file exists and, if it does, it doesn’t have to be rewritten by the web server module. - Phalconphp Doc

      
          RewriteEngine On
          RewriteCond %{REQUEST_FILENAME} !-d
          RewriteCond %{REQUEST_FILENAME} !-f
          RewriteRule ^(.*)$ index.php/$1 [QSA,L]
      
      
    3. index.php***

      Modify the application path and the system path as,

      $system_path = '../system';
      $application_folder = '../application';
      

    Now you use the public folder as base_url()."public/[YOUR ASSET FOLDER]"

    Hope this helps :)

提交回复
热议问题