Codeigniter assets folder best practice

后端 未结 3 811
我寻月下人不归
我寻月下人不归 2020-12-01 01:59

I\'m fairly new to codeigniter, But i\'m learning well, I\'m going to add a css, images, js, ... folder but I\'m not sure where to put it

Someone to

3条回答
  •  广开言路
    2020-12-01 02:59

    I have this setup:

    application
    assets
    system
    .htaccess
    

    and in the "assets" folder i have subfolders like "img" or "js" and so on. I also use "utility helper" to help me point to that folder.

    If you want to try it, you have to first create a helper named "utility_helper.php" with this code:

         

    and store it in

         application/helpers/
    

    then you have to autoload that helper, you go to:

      application/config/autoload.php
    

    and auto load the helper (example: )

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

    you have also to route to that folder ('application/config/routes.php')

           $route['assets/(:any)'] = 'assets/$1';
    

    and have a .htaccess file with this content:

        RewriteEngine on
        RewriteCond $1 !^(index\.php|images|assets|robots\.txt)
        RewriteRule ^(.*)$ /index.php/$1 [L]
    

    now you can simply include external scripts, css example:

       
    

    where css is the folder inside assets and style.css is the css file. Like so:

       application
       assets
              css
                  style.css
       system
    

提交回复
热议问题