Reasons and Solutions of Failure in Loading css and js Files in php ci Framework

  • 2021-07-10 18:58:40
  • OfStack

When integrating html page into ci framework, loading css and js failed, and after half a day, it was found that ci framework was the portal framework.

All requests for files in the framework need to be processed by index. php. When loading external css and js files, make

Use the base_url () function to handle external links.

For example:

base_url in the config configuration file is: "localhost: 8080/Project Name/"

Access the application/resource/aaa. js file in the controller

Relative path < script src= "resource/aaa.js" > < /script > Access failed

1. Output directly in src


<script src= "<?php echo base_url();?>.resource/aaa.js"></script>

2. Borrowing the base tag

Place the output of base_url () in the < base href = " < ?php echo base_url();? > "/ > Inside the label, so in

It is convenient to call inside the page.


<base href = "<?php echo base_url();?>"/>
<script src= "resource/aaa.js"></script>

Related articles: