Home >Backend Development >PHP Tutorial >Reasons and solutions for failure to load css and js files in the php ci framework, _PHP tutorial
When integrating the html page into the ci framework, loading css and js failed. After a long time, I found that the ci framework is the entrance framework,
All requests for files in the framework need to be processed by index.php. When loading external css and js files,
Use the base_url() function to handle external links.
For example:
The base_url in the config configuration file is: "localhost:8080/project name/"
Access the application/resource/aaa.js file in the controller
Relative path2da1ef0a2cbf6a8da3c511edec2ba6cd2cacc6d41bbb37262a98f745aa00fbf0Access failed
1. Output directly in src
<script src= "<?php echo base_url();?>.resource/aaa.js"></script>
2. Borrow base tag
Put the output of base_url() inside the
tagIt is more convenient to call it on the page.
<base href = "<?php echo base_url();?>"/> <script src= "resource/aaa.js"></script>