The solution to failure to load css and js files in ci framework

  • 2021-01-18 06:20:06
  • OfStack

ci is the framework for entry. All requests to files in the framework need to be processed through index.php. When loading external css and js files, use the function base_url () to handle external links.

Such as:

In the config configuration file, base_url is: "localhost:8080/ project name/"

In the controller access application/resource/aaa js file

Relative paths < script src= "resource/aaa.js" > < /script > The visit to fail

1. Output directly in src

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

2, borrow base label

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

It is convenient to call inside the page.
 
< base href = "<?php echo base_url();?>"/> 
<script src= "resource/aaa.js"></script> 

Related articles: